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?
Styling with Markdown is supported
18 January 2014 Reply
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!
Glad you're finding it useful! You can use the PointToImage to convert a point such as that from MouseEventArgs into the appropriate location within the image. You can then use that result to query the bitmap either via Bitmap.GetPixel or via the direct pixels if you have already extracted and stored these via Bitmap.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 a Bitmap object even though the ImageBox uses the more generic Image 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!