C# Programming > Drawing

C# Image Zoom

c# image zoom

Image Zooming

Zooming an image in C# is a task greatly facilitated by GDI+. Programmers working with C#.NET do not have to focus as much on the image processing aspect for zooming into an image, more on the user interface logic.

However it is still a important logic in handling .NET images to maintain speed and efficiency. Yet as previously mentioned, image development in .NET is much easier than other programming languages.

Image Thumbnail

The first task is to create a thumbnail image using GDI+. Now, .NET makes is easy to resize an image, programmers simply give a function the image, the location to draw it, and the new dimensions. There are two things to consider:

First is interpolation. Image interpolation determines the resulting quality of the resized image. More interpolation means a better-looking image, but it takes longer to process. Likewise low interpolation is faster although results are less smooth. Since an image thumbnail is designed to just give the user an overall view of the image, low interpolation is a better option.

The second part to consider is aspect ratio. We want to fit the image into a small thumbnail without distorting the ratio. The source code for this application includes a function called ShrinkToDimensions, which takes a set of dimensions and reduces it to the thumbnail size while maintaining the aspect ratio of the .NET image.


Zooming into the .NET image is achieved by selecting an area to zoom and mapping it into a targeted area. What GDI+ does is clip part of the image (the zoom area part) and then resize the image to the targeted area.

As you can imagine, interpolation plays a role here too, and since we want detail over speed, high interpolation makes more sense.

To increase the amount of image zoom, the dimensions of the selected area are divided by the zoom amount, resulting in a smaller section of the .NET image being expanded to the same target area, thus more zoom.

In order to keep the application efficient, both the original image and the generated thumbnail image are kept in memory and are referenced from there. This allows the application to generate the thumbnail for a new .NET image just once and allows the image zooming to work with small parts of the image.

Additional Features

The sample .NET application has the techniques discussed above. A nice feature is that a generated thumbnail image is scanned for a dominant color (notice the algorithm uses unsafe image processing to be fast). The color is then used to find the opposite color (algorithm borrowed from Dot Net Pulse) to make sure the image zoom selection rectangle stands out in the thumbnail. To change the image zoom selection, just click anywhere in the thumbnail.

In conclusion, c# image zooming is easy with GDI+ and .NET. With proper code logic, image development in .NET is both efficient and fast.

Back to C# Article List