I know this is mostly an image question not code, but I'll give it a shot here.
So first I have a 8bits/pixel grayscale image(bitmap). Which means that each pixel is represented into 1 byte. This means that the the pixel value is the byte value. Clear enough.
But then...
I have a 16bits/pixel grayscale image (bitmap). Which means that each pixel is represented into 2 bytes. This is clear for me. Now I create a byte[] array that will hold each byte value.
For an 1024x1024 image I will have 2097152 bytes. It's 1024*1024*2.
My question is now, how do I get the pixel value for a specific pixel.
Let's say for pixel at position(X|Y) the bytes are 84 and 77. How do I transform these 2 values into the pixel value.
Firstly I need this for some calculation where I need the pixel value, then I want to change the color palette of the bitmap and it works fine with 8 bitsperpixel images, but doesn't for 16bitsperpixel images.
Any help would be nice.
var width = bitmap.PixelWidth;
var height = bitmap.PixelHeight;
var dpiX = bitmap.DpiX;
var dpiY = bitmap.DpiY;
byte[] pixels = new byte[
bitmap.PixelHeight * bitmap.PixelWidth *
bitmap.Format.BitsPerPixel / 8];
bitmap.CopyPixels(pixels, bitmap.PixelWidth * bitmap.Format.BitsPerPixel / 8, 0);
This is how I create the array of pixels.