PixelFormat:为什么没有8bppGrayscale? [英] PixelFormat: why no 8bppGrayscale ??

查看:115
本文介绍了PixelFormat:为什么没有8bppGrayscale?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试使用Bitmap类作为中介将8位灰度TIFF转换为JPEG; [.NET Framework 1.1],但在PixelFormat枚举中似乎有一个令人费解的省略,该枚举描述了位图的可能类型:没有8bppGrayscale! (每像素8位灰度).照原样,默认情况下,我的灰度TIFF变为具有8bppIndexed PixelFormat的位图.这是不好的,因为随后对 myBitmap.Save(filenm,ImageFormat.Jpeg)的调用会产生3频段,这不足为奇对每个像素重复相同亮度值3次的JPEG.这使我得到了灰度的JPEG,但是不必要地导致最终存储库中的存储量增加了3倍.我们正在谈论的是存储库中可能有500,000张图像.

根据我的经验(地理应用),共有3种常用的像素格式:8bppIndexed(通常用于数字化地图),24bppRGB(通常用于彩色卫星图像) )和8bppGrayscale(通常用于灰度卫星图像). PixelFormat枚举省略了8bppGrayscale似乎太惊人了,以至于我想我一定会丢失一些东西.谁能告诉我这是什么吗? (或建议解决方法?)
非常感谢.

Hi All,
I am trying to convert 8-bit grayscale TIFF to JPEG using the Bitmap class as intermediary; [.NET Framework 1.1] but there seems to be a puzzling omission in the PixelFormat enumeration that describes the possible types of Bitmap: there is no 8bppGrayscale ! (8 bits per pixel Grayscale).  As is, my grayscale TIFF becomes a Bitmap with the 8bppIndexed PixelFormat by default.  That's no good, because the subsequent call to myBitmap.Save(filenm, ImageFormat.Jpeg) results, not surprisingly, in a 3-band JPEG where the same luminance value is repeated 3 times for each pixel.  Which gets me a grayscale JPEG, but needlessly results in 3 times as much storage in the final repository.  And we are talking about perhaps 500,000 images in the repository.

In my experience (geographical applications) there are 3 commonly used pixel formats: 8bppIndexed (commonly used for digitized maps), 24bppRGB (commonly used for color satellite imagery) and 8bppGrayscale (commonly used for grayscale satellite imagery).  The omission of 8bppGrayscale from the PixelFormat enumeration seems so astounding that I think I must be missing something.  Can anyone tell me what it is ?  (or suggest a workaround?) 
Thanks much.

推荐答案

要创建灰度位图,请使用带有灰度调色板的Format8bppIndexed格式.您可以使用以下功能来创建灰度调色板:

To create grayscale bitmap use Format8bppIndexed format with grayscale color palette. You can use the following function to create grayscale palette:

       ColorPalette GetGrayScalePalette()
{
          位图bmp =新位图(1,1,PixelFormat.Format8bppIndexed);

        ColorPalette GetGrayScalePalette()
        {
            Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed);

            ColorPalette monoPalette = bmp.Palette;

            ColorPalette monoPalette = bmp.Palette;

            Color []个项= monoPalette.Entries;

            Color[] entries = monoPalette.Entries;

           对于(int i = 0; i< 256; i ++)
           {
             项[i] = Color.FromArgb(i,i,i);
}

            for ( int i = 0; i < 256; i++ )
            {
                entries [ i ] = Color.FromArgb(i, i, i);
            }

           返回monoPalette;
       }

            return monoPalette;
        }


这篇关于PixelFormat:为什么没有8bppGrayscale?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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