Reputation: 952
I am writing a game for Windows 8 in C#. I have an Image and I need to check the color of some given pixel. I know coordinates (x, y) of the pixel in Image, but I can not find any class that can do that. For example
System.Drawing.Bitmap
has method GetPixel
, which would be perfect for me, but I can not use this class in Windows Store apps.
Does anyone know how can I do it? Thanks for any help!
Upvotes: 2
Views: 1146
Reputation: 18823
I haven't used it, but you could try the WriteableBitmapEx class. The project page states that the class has a GetPixel
method.
If you want to implement this yourself (it is not trivial, and takes quite a few function calls), one way is to use BitmapDecoder
to read the bitmap and BitMapDecoder.GetPixelData to get a PixelDataProvider
. From there you can get a byte buffer using DetachPixelData. The byte buffer is a one dimensional array in RGBA format. You'll have to map your x and y coordinates to this array.
Upvotes: 4