user control v/s custom control for image viewer
I would like to create an image viewer. I do not know where to start. Could you please give me some tips to start with.
I have the following point in my mind
- Create a custom control, override the paint event. Use properties to read, flip, rotate and zoom the images
- Create a user control with a panel inside, set the background to the image while i set the public property 'read'. Implement properties 开发者_高级运维to rotate, flip,zoom
I suggest you use WPF instead winforms
Zoom, Pan example using WPF : http://blogs.windowsclient.net/joeyw/archive/2009/06/02/pan-and-zoom-updated.aspx
This topic has sample codes for rotation etc:
This topic provides an introduction to the Microsoft Windows Presentation Foundation Imaging Component. WPF Imaging enables developers to display, transform, and format images.
This topic contains the following sections.
WPF Imaging Component WPF Image Formats Displaying Images in WPF Image Metadata Codec Extensibility Related Topics
You should first Learn GDI+, this book (GDI+ Programming With C#) is very good for
Learning GDI+ after reading , You'll can create an image viewer.
There are numerous ways to show the image, PictureBox springs to mind a part from what you already suggests (http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.aspx).
When it comes to editing, you should avoid GetPixel() and SetPixel() which are beyond slow, and instead gain access to the the bits either through pointers using the unsafe
keyword or by the Marshall Class.
Use the LockBits() method of your bitmap to get a BitmapData-object, and the fun shall begin!
Further reading:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.aspx
https://web.archive.org/web/20121203144033/http://www.bobpowell.net/lockingbits.htm
精彩评论