0

我成功地从他们的原始像素数据中绘制了图像。(只有 8 位图像)。这是做同样事情的代码。

     PixelFormat format = PixelFormat.Format8bppIndexed;
     Bitmap bmp = new Bitmap(Img_Width, Img_Height, format);
     Rectangle rect = new Rectangle(0, 0, Img_Width, Img_Height);
     BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, format);
     Marshal.Copy(rawPixel, 0, bmpData.Scan0, rawPixel.Length);
     bmp.UnlockBits(bmpData);

现在众所周知,c# 2.0 GDI+ 不支持 PixelFormat.format16bppGrayscale。我用谷歌搜索并获得了 3.0/3.5 框架支持。所以我两个都安装了。支持的类是 System.windows.media.PixelFormats。PixelFormats.Gray16

现在我的问题是如何通过传递此参数来创建位图并获取要显示的图像。

我在那里得到了一些 BitmapSource 类,但我在 C#3.0 中很新。

请帮我。

4

2 回答 2

0

尝试这个:

private static Bitmap changePixelFormat(Bitmap input, PixelFormat format)
{
    Bitmap retval=new Bitmap(input.Width, input.Height, format);
    retval.SetResolution(input.HorizontalResolution, input.VerticalResolution);
    Graphics g = Graphics.FromImage(retval);
    g.DrawImage(input, 0, 0);
    g.Dispose();
    return retval;
}
于 2009-05-20T13:24:44.453 回答
0

看看AForge.net中的灰度过滤器。你可以在这里找到来源。

编辑:

作为我链接的那个来源的注释,它使用的是 AForge.NET 的“旧”版本,但概念是相同的。

于 2009-05-20T19:32:06.037 回答