To display the image in the form of your application Graphics Mill for .NET provides a special control called BitmapViewer. This article gives guidelines how to use this control.
To associate the image with the BitmapViewer, you should use the Bitmap property. You can use the Load method to load the image from the file:
BitmapViewer1.Bitmap.Load(OpenFileDialog1.FileName)
bitmapViewer1.Bitmap.Load(openFileDialog1.FileName);
Alternatively, you can assign an existing instance of the Bitmap class to this property. However in this case it is highly recommended to dispose of the image which is currently associated with the BitmapViewer. Otherwise the reference to this image will become orphan, and this image will occupy memory until the garbage collector removes it completely. If the image is quite large, and Bitmap property is updated too often, the application may suddently run out of memory.
To avoid this effect, we recommend to update the Bitmap property with a similar code:
Dim oldBitmap As Aurigma.GraphicsMill.Bitmap = BitmapViewer1.Bitmap BitmapViewer1.Bitmap = newBitmap oldBitmap.Dispose()
Aurigma.GraphicsMill.Bitmap oldBitmap = BitmapViewer1.Bitmap; BitmapViewer1.Bitmap = newBitmap; oldBitmap.Dispose();
After the image stored in the Bitmap property is modified, the control sends the updated image to the client.
Pay attention, the control sends to the client only that portion of the image which is actually visible in the viewport. Moreover, if some part of the image has already been delivered to the client, it is not resent. In brief, the scheme of displaying an image is the following:
true
), the BitmapViewer prepares this image (the
size depends on the PreviewImageResizeRatio
property), saves it in the public cache, and sends it to the client.BitmapViewer allows zooming in two modes: manual and automatic. To maintain zooming, you can use both server and client properties of the BitmapViewer.
Some server properties only have a read-only analogue in JavaScript (for security reasons).
Manual zooming may be done by modifying the Zoom server property or using JavaScript method getZoom/setZoom. When this property equals 1, no zooming is done (i.e. the image is displayed in its actual size). When the property is less than 1, the image is shrunk (e.g. 0.5 means 50% of the actual size), when it is greater than 1, it is stretched (e.g. 3 means 300% of the actual size).
Alternatively you can associate some zooming navigator control, which will zoom the image on the mouse click. You can get more information about it in the topic Using Navigators and Rubberbands (Web Forms).
Image may be zoomed with a different quality. If it is zoomed with low quality, the performance is higher, and vice versa. Also, often low quality is preferable for stretching the image (so that the pixelization effect is visible) since it gives more control when drawing or selecting something. The quality of the zooming is specified with the ZoomQuality property.
Maximum and minimum zoom values can be limited. Use MinZoom and MaxZoom server properties to specify maximum and minimum zoom value correspondingly. You can read these values in the JavaScript using getMinZoom and getMaxZoom methods.
If you need to perform some specific actions when the image is zoomed (e.g. display the zoom factor somewhere), you should handle the Zoomed server event. To be able to handle this event at the client side, use addZoomed/removeZoomed JavaScript methods.
Automatic zooming is used when you need the image to completely fit the control (i.e. occupy maximum area of the control without displaying the scroll bars). It can be set to maintain such zoom ratio to fit the image in the control by width, etc.
To make the control get the zoom ratio automatically, use the ZoomMode server property or the getZoomMode/setZoomMode JavaScript methods. It can be one of the following modes:
Pay attention, when you use zooming navigators, the ZoomMode is automatically reset to None.