gpt4 book ai didi

c# - 在 C#/GDI+ 中从 Format8bppIndexed 转换为 Format24bppRgb

转载 作者:太空狗 更新时间:2023-10-29 20:58:01 25 4
gpt4 key购买 nike

好的,我有一张来自外部应用程序的 8 位索引格式的图像。我需要将此图像转换为大小完全相同的 24 位格式。

我已经尝试创建一个具有相同大小和类型 Format24bppRgb 的新位图,然后使用图形对象在其上绘制 8 位图像,然后再将其保存为 Bmp。这种方法不会出错,但是当我打开生成的图像时,BMP header 具有各种奇怪的值。高度和宽度很大,此外,压缩标志和其他一些值也很有趣(而且很大)。不幸的是,我的特殊要求是将此文件传递给特定的打印机驱动程序,该驱动程序需要具有特定 header 值的 24 位图像(我试图通过 GDI+ 实现)

有人知道将索引文件“向上转换”为非索引 24 位文件的示例吗?如果不是示例,我应该从哪条路径开始编写自己的?

-凯文·格罗斯尼克劳斯kvgros@sseinc.com

最佳答案

我使用下面的代码将图像从 8bpp“上转换”为 24bpp。使用十六进制编辑器检查生成的 24bpp 文件并与 8bpp 文件进行比较,显示两个文件的高度和宽度没有差异。也就是说,8bpp 图像为 1600x1200,而 24bpp 图像具有相同的值。

    private static void ConvertTo24(string inputFileName, string outputFileName)
{
Bitmap bmpIn = (Bitmap)Bitmap.FromFile(inputFileName);

Bitmap converted = new Bitmap(bmpIn.Width, bmpIn.Height, PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(converted))
{
// Prevent DPI conversion
g.PageUnit = GraphicsUnit.Pixel
// Draw the image
g.DrawImageUnscaled(bmpIn, 0, 0);
}
converted.Save(outputFileName, ImageFormat.Bmp);
}

标题中的其他所有内容看起来都合理,图像在我的系统上显示相同。您看到了什么“时髦的值(value)观”?

关于c# - 在 C#/GDI+ 中从 Format8bppIndexed 转换为 Format24bppRgb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/671953/

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