Page 1 of 1

Hittest of transparent areas in images

Posted: 27 Feb 2015, 10:36
by Luro
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.

Re: Hittest of transparent areas in images

Posted: 02 Mar 2015, 20:59
by sfernandez
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..."/>
</Grid>