Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to zoom picture box along with graphics.

this will Zoom the only image part not the graphics part.

C#
public Image PictureBoxZoom(Image imgP, Size size)
{
    Bitmap bm = new Bitmap(imgP, Convert.ToInt32(imgP.Width * size.Width), Convert.ToInt32(imgP.Height * size.Height));
    Graphics grap = Graphics.FromImage(bm);
    grap.InterpolationMode = InterpolationMode.HighQualityBicubic;
    return bm;
}

private void zoomSlider_Scroll(object sender, EventArgs e)
{
    if (zoomSlider.Value > 0 && img != null)
    {
        pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
        pictureBox1.Image = null;
        pictureBox1.Image = PictureBoxZoom(img, new Size(zoomSlider.Value, zoomSlider.Value));
    }
}

the source of image is:

img = Image.FromStream(openFileDialog1.OpenFile());
Picture is zooming but when we draw the rectangle outside image then it's not zooming along with image
Posted
Comments
Ralf Meier 8-Oct-15 7:55am    
Sorry - I don't understand your Problem.
Please give further Information ... Perhaps you improve your Question with some Screenshots ...
piushshukla 8-Oct-15 8:22am    
I dont think u r able to answer.
Ralf Meier 8-Oct-15 8:30am    
OK ... if you believe so ...
In this case I can't help you - perhaps another one can ...
piushshukla 8-Oct-15 8:57am    
Actually I draw the rectangular in picture box but when i want to zoom the picture box then image is zooming but rectangular is not.

Please let me know if you have still confusion.
Ralf Meier 9-Oct-15 0:20am    
Now I think I understand.
But the answer I could give was allready given by Sergey (Solution 1).
If I want to do something like this I would create my own customized PictureBox which has the ability to do what I need.

Are you familiar with creating customized controls (on this Level) ?

1 solution

It's a bad idea to use redundant and primitive control PictureBox if you do something except showing static images. This is some intermediary (control, not image) which only wastes your working time and some extra resource, without giving any benefits in return. If you need to zoom, better render image directly on your own custom control, or some existing control like Panel. Please see my past answers:
Append a picture within picturebox[^],
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^].

And these answers on graphics rendering:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^],
specifically on zoom: Zoom image in C# .net mouse wheel[^].

Also, if you plan to zoom in some bitmap image (that is, enlarging it above its original size in pixels), it also would be a bad idea, because you will get prohibitively poor quality. If you really need so, always provide original image with the size equal or just a bit smaller then the maximum zoom size. Better yet, resort to vector graphics, if it's possible.

—SA
 
Share this answer
 

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