Create an effect of magnifying glass for a picturebox

3.5k views Asked by At

I would like to know how to create an effect of a magnifying glass for a picturebox. Not zooming the picturebox but magnifying a part of the the image in the PictureBox control (circle or rectangle) and setting the size of the glass and the magnification factor.

It may only work within the picturebox control.

Language: C#

Thanks in advance !

2

There are 2 answers

1
Kamyar On

Basically, you'd need two pictureboxes. One for the whole image and another for the magnified section. Also, you have to place the magnified picturebox according to user's mouse position.

You'll find a good article about it at http://www.codeproject.com/Articles/21097/PictureBox-Zoom. Just change the source to show the second picturebox in appropriate place (under user's cursor position).

0
Na Na On

You need 2 picturebox objects, one for picture itself and second for magnified area.

Next load picture into memory, you haven't specified source of the picture but in any case I recommend using streams.

Then create bitmap image in memory.

Using Image method set property of a picturebox.

To create source image for magnifying picturebox you need to clone selected part (calculating dimensions of a new picture area). Whole thing is not as trivial as you may expect as clone method accepts Rectangle objects as an area selector and generally works on rectangles rather than circles to copy selection.

I also recommend to Dispose() unused bitmap objects as soon as possible.

Hope this helps.