First of all, this is not a complicated control. The goal is to create a user control in which you can drag drop a Button or Label and all the methods and properties that are related to your/my daily image viewing needs.
The idea came when I wanted to create a generic viewer that could load almost anything from the browser like PDF, Word/Excel (Office), image etc. in just one interface. Hopefully, this can help a lot of people who needs image viewing in their projects.
This can be used for Win32 supported images like BMP, JPG, GIF etc., and also for multipage images like TIFF.
Using the Code
To use the control, you must first add the DLL to the references. After that, you add the directive with the
Daclare the viewer object and instantiate it.
private ALVImageViewer alvImageViewer1;
this.alvImageViewer1 = new ALVImageViewer();
Once this is done, you can now use its different methods/properties during the events triggered by your buttons etc.
You just create a button for Flip left/Flip Right, Rotate left and right, Zoom in and Zoom Out. A radio button for Auto Fit To Screen (locates best fit by the width and height of the control), Auto Fit By Width (based on the width of the control) or by Height (you know..).
The very first step is loading an image file:
Now, based on whether any of the fit types is selected (the default is always fit to screen), the image should load appropriately. To get the original image size, just set all the AutoFit properties to false. (Note that when you set auto-fit to true, if there is another auto-fit that is active, it will deactivated or set to false.)
Here are the rest of the methods you need to know:
alvImageViewer1.Rotate90Left(); alvImageViewer1.Rotate90Right(); alvImageViewer1.FrameMoveTo(pageNo) alvImageViewer1.FlipHorizontal(); alvImageViewer1.FlipVertical(); alvImageViewer1.ZoomRatio
The zoom ratio is used for the zoom in and out feature. I limited the max value to 10 and min value to 0.1. The zoom ratio is actually the scale of the image where 1.0 is 100% or the real size of the image, 2.0 is 2x the original scale of the image, and 0.1 is 1/10th of the original image scale. The zoom ratio "will" always be set to something else "if" any of the auto-fit properties is set to true. So, if you have Fit To Width set to true, then the image will scale the zoom ratio to the size that will fit by width, and whenever you try to change the zoom ratio to something else, the control would just ignore the command.
Points of Interest
Creating the control was not that easy. Sometimes you don't understand how the bugs happen, like image view missing and scroll bars not responding correctly etc. But, after a day's work it's all worth it. I will upload a better version if I add PDF and Office support.
- September 2004 - Image Viewer was created with Notepad and .NET SDK 2003.
- April 2005 - GUI for version 1.0.
- July 2007 - DMS project revision into VB.NET because the project leader does not know C# or VB.NET, so I had to switch to something it "might/possibly or hopefully" be familiar with.
- September 2007 - 2005 GUI recreated because I lost the old one, and this is much better I believe.