I have 16 bit depth image from that I want to read only pixel data and store it to byte[]
I tried following code :
FileInfo fileInfo = new FileInfo("C:\\Image stitch API\\Temp\\output.tif");
byte[] data = new byte[fileInfo.Length];
I also tried the following :
Image img;
img = Image.FromFile("C:\\Image stitch API\\Temp\\output.tif");
ImageConverter ic = new ImageConverter();
byte[] data = (byte[])ic.ConvertTo(img, typeof(byte[]))
Here all data it is coming from image, but I need only pixel data?
Can any one help on this?
If you can load your image as Bitmap, it is pretty easy to get pixel info as shown below.
Bitmap bitmap = new Bitmap("somefile.ext");
Color color = bitmap.GetPixel(x,y)
GetPixel() will return Color (struct) type and you can get individual channel values as byte like shown below.
byte g = slateBlue.G;
byte b = slateBlue.B;
byte r = slateBlue.R;
byte a = slateBlue.A;
Regarding your comment, I will suggest you to use use Netvips to manipulate image in byte array form (it is way betterand faster than system.drawing). By doing so, you could get image bands as byte arrays as below.
var imageBands = inputImage.Bandsplit();
var R = imageBands [0];
var B = imageBands [1];
var G = imageBands [2];
If you dont wanna switch the libraries, you could get byte array with System.Drawing like shown below.
byte[] image = new[] {R, B, G};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With