Click here to Skip to main content
13,088,439 members (55,643 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Can I zoom in/out a GraphicsPath rasteredly in C#? I tried using Matrix.Scale() method to simulate zooming in/out a GraphicsPath, but it seems that the GraphicsPath is vectoredly zoomed in/out, I want it to be rasteredly zoomed in/out (like when you draw an oval in MS Paint and zoom in/out that oval, the zoomed shape is rastered).

Could you please show me any way to achieve this thing, I need something effective in performance (no flickering). The overall idea of mine is drawing some shapes on a form and try zooming in/out those shapes like as you do in MS Paint.

Your help would be highly appreciated!


Here are links to images that you required to see:

#1 1xZoom

#2 4xZoom using Matrix.Scale() method, this is what I tried first

#3 4xZoom - This is what I want

#4 4xZoom - This is what I have when using the method suggested by you, it is a real rastered shape

Thank you for your time to dig into my problem!!!
Posted 11-Feb-13 19:00pm
Updated 12-Feb-13 5:15am
Bad idea...
supernorb 12-Feb-13 4:05am
Why do you think it is a bad idea? I want to achieve the same thing when zooming in MS Paint, user wants to zoom in a shape to view the pixels in large scale, if zooming vectoredly, the whole shape is zoomed but the pixels are not. For example, the shape contains 100 pixels, when being zoomed rasteredly it still contains 100 pixels (in larger size) meanwhile it should contain more 100 pixels when being vectoredly zoomed in and less 100 pixels when being vectoredly zoomed out.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You could draw the path onto a bitmap and zoom into that. But the pixels will get interpolated, even with Graphics.SmoothingMode set to None.
So if you really want to see pixels, you will have to repeatedly FillRectangle. One square for each pixel of the mentioned bitmap.

Oh, and ... Why?

Bitmap ZoomPixelish(Image original, int scaleFactor)
    bitmap zoomedImage = new Bitmap(original.Width * scaleFactor, original.Height * scaleFactor);
    Graphics g = Graphics.FromImage(zoomedImage);
    for(int y = 0; y < original.Height; y++)
        for(int x = 0; x < original.Widht; x++)
                new SolidBrush(original.GetPixel(x,y)),
                x * scaleFactor,
                y * scaleFactor,

That's not tested. But you should get the intention. Bugfixing and optimization are up to you (a black-and-white image doesn't need a new SolidBrush for every pixel; LockBits instead of GetPixel)
supernorb 12-Feb-13 4:18am
I tested the way you suggested but it is not what I want, in fact I said 'rasteredly' but it is not really 'rastered', I think exactly saying, it is 'vectored by pixel' not by the whole shape, for example, you zoom in the shape by 8x, each pixel of the shape will be zoomed in vectoredly by 8x not the whole shape. I hope you understand what I want, and I'm also sorry for the unclear expression what I want in my question. Thanks!!!
lukeer 12-Feb-13 5:25am
Actually, no. I don't get it.
Could you create images of
1. Scene in 1xZoom
2. Scene in 4xZoom the way it is now
3. Scene in 4xZoom the way you want it to be?
supernorb 12-Feb-13 11:17am
OK, please see my update! I hope this time you will get what I want to explain! Thank you!
lukeer 13-Feb-13 1:17am
I think I know what you want. I updated my answer accordingly to outline what I meant with the "repeatedly FillRectangle" part.
supernorb 13-Feb-13 5:02am
Your code should work but I wonder if it is the only approach to solve my problem? I really care about the performance of drawing. In fact I'm building a MS Paint like application. Thank you for your help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100