Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 11-Feb-13 20:00pm
supernorb2.6K
Edited 12-Feb-13 6:15am
v2
Comments
Sergey Alexandrovich Kryukov at 12-Feb-13 1:05am
   
Bad idea...
—SA
supernorb at 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
good
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?
 
[Edit]
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]
  Permalink  
v3
Comments
supernorb at 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 at 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 at 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 at 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 at 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
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
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