Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
112 views
in Technique[技术] by (71.8m points)

c# - Detecting mouse move in a transparent image

I have an image on my form which is a PNG of a car, and the background is transparent. In C# I am using e.Graphics.DrawImage to draw to the screen, but I want to be able to check when the mouse is moved over the image, but NOT the transparent part of the image.

Update: I had been previously drawing rectangles around the image and checking if mouse was inside the rectangle or not, but that was for the whole image not the non-transparent part of the image.

What would be the best way of going about this,

Thanks in advance

Mark

question from:https://stackoverflow.com/questions/65848625/detecting-mouse-move-in-a-transparent-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have solved it now!

I drew a rectangle around the image, and on the mouse move event, I retrieved the current pixel from the cursor location, and then got the Alpha channel from the colour. Then just checked for when the Alpha channel was not equal to 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...