Image in a Panel

  • Thread starter Thread starter Alberto
  • Start date Start date
A

Alberto

I have an image loaded in a panel and I was trying to make a zoom on it. I
still doesn't know how to do it but I was trying to access to the image
loaded in the panel.
Could you help me?
Thank you.
 
Alberto,

You will have to custom paint the image onto the panel. Basically, what
you want to do is select the area of the image that you want zoomed, and
then in the event handler for the Paint event, you want to call DrawImage,
selecting the area of the image that you want, and indicating what area on
the panel you want it to paint. The Graphics class will take care of the
stretching for you.

Hope this helps.
 
Derive an object from ScrollableControl that paints the image.

In the OnPaint method, you can create a Matrix that defines the pan and zoom
of the object, then just draw the image as normal.

Here's a bit of code from a canvas class I wrote. It handles infinite
zooming and panning using the AutoScroll abilities of a scrollable control

in the OnPaint....
Matrix mx=new Matrix(_zoom,0,0,_zoom,0,0);

Size s=new
Size((int)(this.ClientSize.Width*(1f/_zoom)),(int)(this.ClientSize.Height*(1
f/_zoom)));

if(s.Width>PageSize.Width)

mx.Translate((s.Width/2)-(_pageSize.Width/2),0);

else

mx.Translate((float)this.AutoScrollPosition.X*(1f/_zoom),0);

if(s.Height>PageSize.Height)

mx.Translate(0,(s.Height/2)-(this._pageSize.Height/2)+(this.AutoScrollPositi
on.Y));

else

mx.Translate(0,(float)this.AutoScrollPosition.Y*(1f/_zoom));

e.Graphics.Transform=mx;

//Paint here...

HTH



--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
Back
Top