Reply to comment
While we appreciate comments from our users, please follow our posting guidelines. Have you tried the Cyotek Forums for support from Cyotek and the community?
While we appreciate comments from our users, please follow our posting guidelines. Have you tried the Cyotek Forums for support from Cyotek and the community?
Dave Gordon
#
Hi, Excellent ImageBox; which I am using in a series of articles over on MSDN.
When we are zoomed in, the Mouse XY coordinates do not relate to the actual Zoomed image coordinates. So we are unable to detect what colour the mouse is hovering over as the mouseXY coordinates differ from the virtual coordinates of the zoom.
How do we get the colour of the pixel the mouse is over regardless of the zoom or panning of the image within the ImageBox container?
Thanks again Richard!
Richard Moss
#
Glad you're finding it useful! You can use the
PointToImage
to convert a point such as that fromMouseEventArgs
into the appropriate location within the image. You can then use that result to query the bitmap either viaBitmap.GetPixel
or via the direct pixels if you have already extracted and stored these viaBitmap.Lockbits
. (The former is going to be slow, especially if you are going to be updating as you move the mouse around, whilst the latter is complicated to explain especially if you use pointers). Both of these assume you are using aBitmap
object even though theImageBox
uses the more genericImage
instead. Although now that I think, I've never tested (or used for that matter) a metafile.PS: I noticed in your article that you're linking to an older version of the code. Might be better to link to the GitHub page for this project instead (https://github.com/cyotek/Cyotek.Windows.Forms.ImageBox) or it's NuGet package (https://www.nuget.org/packages/CyotekImageBox/). Hmm, or maybe I should add an overview page to this site instead of scattered blog posts.
Hope that helps! Regards