Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Picture boxes have the option to choose the picture mode in the properties, one of these modes is zoom mode, how do I achieve that same zoom mode effect with a graphics object?

Regards,
Jordan
Posted
Comments
Sergey Alexandrovich Kryukov 20-Nov-13 13:33pm    
What do you mean by "graphic object"? Of course, no PictureBox...
—SA
Sicppy 20-Nov-13 13:36pm    
The graphics object, System.Drawing.Graphics
Sergey Alexandrovich Kryukov 20-Nov-13 14:38pm    
For System.Drawing.Graphic (yes, this is a right approach), I already answered in detail, please see my answer and links. Most likely, you can ignore first part where I warn against PictureBox, go right to the link Zoom image in C# .net mouse wheel.
Any problems?
—SA

Even if you do just the zoom, or anything else beyond showing static picture in PictureBox, this is a clear indicator that you should throw off this nearly pointless control and render graphics by yourself, which would be much easier. In such cases, PictureBox could be used, but it will only eat up your development time and some extra resources giving nothing in return.

Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

I explained zoom specifically in my past answer: Zoom image in C# .net mouse wheel[^].

See also these past answers on rendering in System.Windows.Forms:
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
Drawing Lines between mdi child forms[^],
How to speed up my vb.net application?[^].

[EDIT]

If you need to know how to re-sample a bitmap (please see my comment below), please see other past answers:
resize image in vb.net[^],
Read Big Tiff and JPEG files (>(23000 x 23000) pix) in a stream. And display part of it to the screen in realtime.[^].

—SA
 
Share this answer
 
v2
Comments
Sicppy 20-Nov-13 13:40pm    
I think you are missing the question, I do want to do it with a graphics object, but I want to display the image, the same way a PictureBox zoom mode does, try this, make a new form, put a picturebox in it, click the right facing arrow in the top right corner of the picture box, and click dock in parent container. then click the arrow again, click the drop down arrow, and hit zoom. then load any image into it, run the program and try re-sizing the form, thats the effect I want to create, but with the Graphics object.
Sergey Alexandrovich Kryukov 20-Nov-13 14:43pm    
That's why I asked you a question in my comment to your question. You answered, thank you. Go right to that link. Anyway, all my recommendations are the same, nothing missing.
Is it a bitmap? or vector graphics? If you are unfortunate enough to work with bitmaps, you need to remember that you have to have a biggest possible original image and re-sample it down. Re-sampling of anything up would mean really bad quality. I'll add a reference to the answer of bitmap re-sampling.
—SA
Sicppy 20-Nov-13 15:25pm    
It is actually an animated GIF, which is my my first instinct was to use a PictureBox, but I strayed away because as you mentioned, it is almost completely pointless.
Sergey Alexandrovich Kryukov 20-Nov-13 15:35pm    
I see. You should have mentioned about animated GIF in first place. You would need to re-sample it, all frames. The GIF technology itself is not so adequate. First thing I would think of would be migrating away from animated GIF to animated vector graphics. It depends on what is pictured on this graphics, could be pretty simple. (The simplest way to make such graphic would be WPF, by the way.) I mean, using such primitive animation as GIF and zooming are two somewhat contradictory things, it is really designed for small-size fixed-size animated images. "Real" high-resolution animation is a different story, it is usually zoomed well...
—SA
There are hundreds of thousands of .NET programmers that use the PictureBox Control, and there is nothing wrong with it. WPF offers much more functionality for "clean" scaling of vectors, or bitmaps, than WinForms which uses the older GDI+ graphics engine.

If you are working with an animated Gif file, scaling it arbitrarily is probably going to be problematic, and, whatever .NET facility you use, you'll have to deal with maintaining aspect ratio as you scale.

There are some special problems using Gif files with the WinForms GDI+ graphics engine, and any robust re-sizing is going to require you deal with image color quantization and color palette. See the discussion here: [^].

These resources may prove helpful to you: [^], [^].

Very useful C# code for image resize here: [^].
 
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