gpt4 book ai didi

c# - 在图像为 16bpp 灰度时从位图中获取彩色图像

转载 作者:太空宇宙 更新时间:2023-11-03 14:36:30 25 4
gpt4 key购买 nike

问题一。 My own Related problem

我在这里问了下一个问题

现在是第 2 个问题。

当我尝试从原始像素数据打开 16 位(单色)图像时然后我收到错误。因为我在创建位图时使用 PixelFormat.Format16bppGrayscale

Bitmap bmp = new Bitmap(Img_Width, Img_Height,PixelFormat.Format16bppGrayscale);

所以用谷歌搜索,发现不支持 Format16bppGrayscale,所以我修改了我的代码,如下所示。

 PixelFormat format = PixelFormat.Format16bppRgb565;
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);

令人惊奇的是,我现在正在获取图像,因为我更改了像素格式。但问题是我的单色(灰度)图像看起来有各种颜色。

怎样才能得到原来的样子。我尝试了几种灰度方法但没有成功请给我一些不安全的代码。谢谢,

最佳答案

BobPowell's GDI+ FAQ has a bit about greyscale 。 .NET 中的 16 bpp 根本不起作用。我必须以 32 bpp 的速度完成所有工作,并求助于外部工具进行转换。幸运的是(?)我大部分时间都坚持使用 TIFF 图像。此外,this thread 可能会有所帮助。

关于c# - 在图像为 16bpp 灰度时从位图中获取彩色图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/797721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com