Sabtu, 16 Mei 2015

Pan and Zoom Very Large Images ( membuat zoom&pan gambar)

Introduction

I recently wrote an article showing a simple method for panning an image. The code


worked very well for small to moderate sized images. However, when using very large images, the performance degraded significantly.That article used a picture box within a panel, and used the auto scroll functionality of the panel to perform scrolling. I received quite a bit of feedback indicating the need for a version that could handle very large images and still pan very smoothly. I also received requests for ideas on how to zoom the image in and out. So, I got to work.What I came up with is a control that could smoothly pan super-sized images, and also provided zoom functionality. My tests were with a 49MB GIF (7000 x 7000). The performance was very smooth. Of course, the control works equally as well with small images. The control is demonstrated in the included sample
project.This custom control does not use a picture box, nor does it inherit from one. Neither is there a panel or any "auto-scrolling". This is very different and very much a better way of panning an image (in my opinion). An added benefit to this example is the ability to zoom the image withoutresizing a picture box (which can get quite large in memory).

How It Works

Only paints the part of the image currently visible.Double-buffering provides flicker free panning.GDI+ automatically scales the image for us.

Public Properties

Public Property PanButton() As System.Windows.Forms.MouseButtonsPublic Property ZoomOnMouseWheel() As BooleanPublic Property ZoomFactor() As DoublePublic Property Origin() As System.Drawing.Point

Public Shadows

Public Shadows Property Image() As System.Drawing.ImagePublic Shadows Property initialimage() As System.Drawing.Image

Public Methods

Public Sub ShowActualSize()
Public Sub ResetImage()
Using the control is as simple as using a standard PictureBox. First, drop the control on a form, then when you need to show an image, you can do it this way:

Dim bmp As New Bitmap("Image.jpg")

 Me.ImageViewer1.Image = bmp...baca lanjut