WPF Cursor on a partially transparent image
I have a png that contains transparent regions and I set it to the image tag but how am I able to set the cursor to a hand when it is over an opaque part of the image?
Thanks Tony
To do this you will need to look at the bitmap itself. WPF's hit testing mechanism considers any pixel painted ith a "transparent" brush to still be clickable even though invisible. This is normally a good thing but gets in the way of what you're trying to do. Because a .png paints with the transparent brush, the entire .png is considerd as painted when doing hit testing.
What you need to do in your MouseMove
event handler is:
HitTestResult
you get back, check to see if it is an Image
and if so, whether a transparent pixel is under the mouse Cursor
value based on what the mouse is over To determine whether a the mouse is over a transparent pixel of an image:
e.GetPosition(image)
) BitmapSource.CopyPixels
to copy a 1-pixel rectangle into an array (ie. only the single pixel the mouse is over) 上一篇: 抛出异常会导致分段错误
下一篇: WPF光标在部分透明的图像上