从Format8bppIndexed到Format24bppRgb转换在C#/ GDI + [英] Converting from a Format8bppIndexed to a Format24bppRgb in C#/GDI+

查看:1801
本文介绍了从Format8bppIndexed到Format24bppRgb转换在C#/ GDI +的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个图像中的8位索引格式从外部应用程序未来通过。我需要这个图像转换成精确的相同尺寸的24位格式。



我已经尝试创建相同大小Format24bppRgb和类型的新位图,然后使用一个图形对象在它绘制8位图像保存为前一个BMP。这种方法不会报错了,但是当我打开生成的图像BMP头拥有各类时髦的值。高度和宽度是巨大的,此外,也有压缩标志和其他一些有趣的(大)值。不幸的是我的特殊要求是通过这个文件,关闭到需要用特定的标头值的24位图像(我正在尝试通过GDI +来实现)



<特定的打印机驱动程序p>任何人都知道的上转换的索引文件,以一个不索引24位文件的示例的?如果没有一个例子,我应该开始的路径向下写我自己?



-Kevin Grossnicklaus
kvgros@sseinc.com


解决方案

我用下面的代码为向上转换将图像从8bpp至24 bpp的。用十六进制编辑器检查所生成的24 bpp的文件和对8bpp文件进行比较示出的高度和宽度中的两个文件没有区别。也就是说,8bpp图像是1600×1200,并支持24 bpp图像具有相同的价值观。

 私有静态无效ConvertTo24(字符串查找inputfilename,串outputFileName)
{
位图bmpIn =(位图)Bitmap.FromFile(查找inputfilename);

位图转换=新位图(bmpIn.Width,bmpIn.Height,PixelFormat.Format24bppRgb);使用
(图形G = Graphics.FromImage(折算))
{
//防止DPI转换
g.PageUnit = GraphicsUnit.Pixel
//绘制图像
g.DrawImageUnscaled(bmpIn,0,0);
}
converted.Save(outputFileName,ImageFormat.Bmp);
}



其他的一切在头看起来合理,图像显示在我的系统相同。什么时髦价值观你看见了什么?


Alright, I have an image coming through from an external application in an 8-bit indexed format. I need this image converted to a 24-bit format of the exact same size.

I've tried creating a new Bitmap of the same size and of type Format24bppRgb and then using a Graphics object to draw the 8-bit image over it before saving it as a Bmp. This approach doesn't error out but when I open the resulting image the BMP header has all kinds of funky values. The height and width are HUGE and, in addition, there are funny (and large) values for the compression flags and a few others. Unfortunately my particular requirements are to pass this file off to a specific printer driver that demands a 24-bit image with specific header values (which I'm trying to achieve through GDI+)

Anyone know of an example on "up-converting" an indexed file to a not-indexed 24-bit file? If not an example, which path should I start down to write my own?

-Kevin Grossnicklaus kvgros@sseinc.com

解决方案

I used the code below to "up-convert" an image from 8bpp to 24bpp. Inspecting the generated 24bpp file with a hex editor and comparing against the 8bpp file shows no difference in height and width in the two files. That is, the 8bpp image was 1600x1200, and the 24bpp image has the same values.

    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);
    }

Everything else in the headers looks reasonable, and the images display identical on my system. What "funky values" are you seeing?

这篇关于从Format8bppIndexed到Format24bppRgb转换在C#/ GDI +的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆