相关疑难解决方法(0)

原始像素数组到灰度BitmapImage

我有一组原始像素数据.我想将其转换为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;
}
Run Code Online (Sandbox Code Playgroud)

位图看起来像彩色图像而不是灰度.

c# bitmap

3
推荐指数
2
解决办法
1546
查看次数

标签 统计

bitmap ×1

c# ×1