【发布时间】:2013-03-28 20:02:18
【问题描述】:
我需要从 System.Drawing.Bitmap 的 alpha 通道生成灰度位图。
我尝试使用 GetPixel 和 SetPixel,但这不适用于 PixelFormat 为 Format16bppGrayScale 的位图。
例如,将我的灰度图像中的所有像素设置为黑色。 SetPixel 抛出异常。
var bitmap = new Bitmap(16, 16, PixelFormat.Format16bppGrayScale);
for (int x = 0; x < bitmap.Width; x++)
{
for (int y = 0; y < bitmap.Height; y++)
{
bitmap.SetPixel(x,y, Color.Black);
}
}
【问题讨论】:
-
您能否展示您的代码并指出哪些部分不适用于 16bppGrayScale 图像?