开发者

magnifier in c# .net

开发者 https://www.devze.com 2023-03-05 07:10 出处:网络
I have drawn an image in a panel. When I check a \'Magnify\' check box and place mouse cursor开发者_如何学编程 over the panel, the rectangle area covering the cursor should be magnified. How can I do

I have drawn an image in a panel. When I check a 'Magnify' check box and place mouse cursor开发者_如何学编程 over the panel, the rectangle area covering the cursor should be magnified. How can I do it? I searched Codeproject.com and did not find such one.


This is how you do this in WPF

In WinForms it is not that easy but still doable. You have to add the control on top of the picturebox and move it around with the cursor (and adjust the origin in of the image in the magnifier to move along).


I did something similar a long time ago but I don't know if it was the best approach or better approaches exist today. I determined a mapping of my viewing area by magnification strength to individual pixels. Each pixel on the regular image represented a small Rectangle of varying size depending on magnification level and it had the same color attribute as the pixel as well.

I figured out how many Pixel Rectangles I could fit in my viewing area and then used that to figure out the snapshot rectangle size on the original. I read through every pixel top to left until I reached bottom left, and in the snapshot creating these rectangles for each pixel and placing them in the viewing area image one after the other.

It worked decently well and was pretty fast but I had to double buffer the viewing image panel to get updates. A big problem with this approach was that I couldn't zoom out from the original.

Like I said I am sure their are better ways to do this as I was just whipping something together at the last minute.

0

精彩评论

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

关注公众号