开发者

Zooming an image inside a picture box

I'm have a picture box control and 2 Command Buttons. I have开发者_StackOverflow社区 an image displayed inside the picture box.

Is it possible to zoom the image when the Zoom-in and Zoom out buttons are clicked?

Or I can even put a scroll bar. Is it possible to zoom the image according to the scroll bar movements?

I'm using VB 6.


I assume here that you are using BMP or JPG files here.

The simple scratch method is to place an Image control in the PictureBox, initially with the property Stretch = False. Initially, it would be in the top left hand corner. After setting the Picture property to your picture object, the Image control will be resized to fit the image. Save the original width and height of the control in variables. Now set Stretch = True. You can zoom in by resizing the image using

img.Move 0, 0, sngWidth * sngMagFactor, sngHeight * sngMagFactor

Where sngMaxFactor = 4! or however much you want to zoom by.

Restore back to original size by:

img.Move 0, 0, sngWidth, sngHeight

You can also pan the zoomed image by altering the Left and Top arguments in the Move() method.


It might be easiest to use two pic boxes, one inside the other. The 'outer' box can be thought of as a viewport into the 'inner' box, which you resize and position as needed. The effect will be the same but the coding is much simpler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜