c# - raw pixel array to gray scale BitmapImage -
i have array of raw pixel data. convert 8bpp bitmap.
public static bitmap bytetograybitmap(byte[] rawbytes, int width, int height) { bitmap bitmap = new bitmap(width, height, pixelformat.format8bppindexed); bitmapdata bitmapdata = bitmap.lockbits(new rectangle(0, 0, width, height), imagelockmode.writeonly, bitmap.pixelformat); marshal.copy(rawbytes, 0, bitmapdata .scan0, rawbytes.length); bitmap.unlockbits(bitmapdata); return bitmap; }
bitmap looks color image instead of grayscale.
try adding before return bitmap:
for (int c = 0; c < bitmap.palette.entries.length; c++) bitmap.palette.entries[c] = color.fromargb(c, c, c);
it create typical grayscale palette.
Comments
Post a Comment