0

How can I detect transparent pixels in an image using WPF so that I know where a user clicks?

Brad Rem
  • 6,036
  • 2
  • 25
  • 50
in4man
  • 351
  • 1
  • 3
  • 6
  • i think most people's first question back to you is WHY do you need to detect transparent pixels? we probably would have a better answer about what you're trying to do than HOW you're trying to do it. What do you need to do with the transparent pixels? – John Gardner Aug 02 '10 at 18:04
  • WHY to detect where user click picture – in4man Aug 05 '10 at 18:48

1 Answers1

0

U don't need Image class, it is not design for pixel manipulation. Rater use Bitmap* class

BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"/test.png",UriKind.RelativeOrAbsolute);
bi.EndInit();

an exapmle

Implement public PixelColor[,] GetPixels(BitmapSource source) method and then interate through returned array to find Alpha channel ( a simple loop). Mind that some images does not support transparency and the file vary depends on structure (ARGB, RGBA) etc.

Community
  • 1
  • 1
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108