Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 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!
Thanks!

UPDATE!!!

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
Updated 12-Feb-13 5:15am
v2
Comments
Sergey Alexandrovich Kryukov 12-Feb-13 1:05am    
Bad idea...
—SA
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

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?

[Edit]
C#
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++)
        {
            g.FillRectangle(
                new SolidBrush(original.GetPixel(x,y)),
                x * scaleFactor,
                y * scaleFactor,
                scaleFactor,
                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)
[/Edit]
 
Share this answer
 
v3
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900