How to apply a fade transition effect to Images using a Timer?

There are some problem to fix here: → fadeTimer.Interval = 10;: You’re (possibly) using the wrong Timer: the System.Timers.Timer’s Elapsed is raised in a ThreadPool Thread. Unless you have set the SynchronizingObject to a Control object, which is then used to marshal the handler calls, referencing a Control in the handler will cause trouble (cross-thread … Read more

Using a matrix to rotate rectangles individually

I would use a function similar to this: public void RotateRectangle(Graphics g, Rectangle r, float angle) { using (Matrix m = new Matrix()) { m.RotateAt(angle, new PointF(r.Left + (r.Width / 2), r.Top + (r.Height / 2))); g.Transform = m; g.DrawRectangle(Pens.Black, r); g.ResetTransform(); } } It uses a matrix to perform the rotation at a certain … Read more

GDI+ / C#: How to save an image as EMF?

Image is an abstract class: what you want to do depends on whether you are dealing with a Metafile or a Bitmap. Creating an image with GDI+ and saving it as an EMF is simple with Metafile. Per Mike’s post: var path = @”c:\foo.emf” var g = CreateGraphics(); // get a graphics object from your … Read more

Drawing a transparent button

WinForms (and underlying User32) does not support transparency at all. WinForms however can simulate transparency by using control style you provide – SupportsTransparentBackColor, but in this case all that “transparent” control does, it to allow drawing parent its background. ButtonBase uses some windows styles that prevent working this mechanism. I see two solutions: one is … Read more

JPEG 2000 support in C#.NET

Seems like we can do it using FreeImage (which is free) FIBITMAP dib = FreeImage.LoadEx(“test.jp2”); //save the image out to disk FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, dib, “test.jpg”, FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYNORMAL); //or even turn it into a normal Bitmap for later use Bitmap bitmap = FreeImage.GetBitmap(dib);

Drawing a Long String on to a Bitmap results in Drawing Issues

When drawing a string of characters (ASCII or a form of Unicode encoded symbols) using Graphics.DrawString() with a fixed sized Font, the resulting graphics appear to generate a sort of grid, degrading the visual quality of the rendering. A solution is to substitute the GDI+ Graphics methods with the GDI methods, using TextRenderer.MeasureText() and TextRenderer.DrawText(). … Read more