Topic Author
Posts: 3
Joined: 18 Feb 2015, 10:22

Hittest of transparent areas in images

27 Feb 2015, 10:36

We want to implement Drag&Drop with images which also have transparent areas.
We need to test if the player clicked on a transparent area on the image or not.
Is there a way to read the alpha value of a pixel of the image?

Or how would you solve this issue of transparent areas that should not react to Mouse Inputs?

Edit: We are using the C++ Version.
User avatar
Site Admin
Posts: 2422
Joined: 22 Dec 2011, 19:20

Re: Hittest of transparent areas in images

02 Mar 2015, 20:59

There is no API in NoesisGUI to access pixel information from an ImageSource. In WPF it can be done if your ImageSource is a BitmapImage, and you need to copy the entire image to a memory buffer to be able to read the pixel value (sample here). We will study to incorporate this approach in the future, but not sure.

My advice is to use a path that covers the solid areas of your image (an image can be traced into vectors easily with many tools) to catch the hit testing, and make the image non visible for hit testing:
<Grid x:Name="Arrow">
  <Image Source="arrow.png" IsHitTestVisible="False"/>
  <Path Data="M0,0L10,0..."/>

Who is online

Users browsing this forum: No registered users and 2 guests