Hit Test Image Content

1.2k Views Asked by At

I want to hit test the content of an image. In order to do that I created BitmapImage and draw it inside DrawingVisual using DrawingContext.DrawImage() method. When it is hit tested, using VisualTreeHelper.HitTest(), every point in image returns true however I want white pixels to return false and non-white pixels to return true. So I converted BitmapImage to black and white pixel format using FormatConvertedBitmap but it didn't work also. Any suggestions? It would be better if I can hit test against ImageDrawing object.

1

There are 1 best solutions below

1
On

Two suggestions:

  1. Try using transparent pixels, not white
  2. You may need to implement your own hit testing logic. For a Visual this means overriding HitTestCore.