1

我正在打开不同类型的图像,例如(8 位和 16 位),它们是(单色、RGB、调色板颜色)。

我有这些图像的原始像素数据。我为 8 位图像创建这样的位图。

          //for monocrome images i am passing PixelFormat.Format8bppIndexed.
          //for RGB images i am passing PixelFormat.Format24bppRgb
           PixelFormat format = PixelFormat.Format8bppIndexed;
           Bitmap bmp = new Bitmap(Img_Width, Img_Height,format);

           Rectangle rect = new Rectangle(0, 0, Img_Width, Img_Height);

           //locking the bitmap on memory
           BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, format);

           // copy the managed byte array to the bitmap's image data
           Marshal.Copy(rawPixel, 0, bmpData.Scan0, rawPixel.Length);
           bmp.UnlockBits(bmpData);

问题是,当我绘制该 bmp 图像时,它的颜色与原始图像不同。那么有什么方法可以在彩色图像上应用 lut(查找表)。

我想要任何不安全的代码,因为我尝试了 getixel 和 setPixel 并且它们非常慢。我也不想要 Image.fromSource() 方法。

4

4 回答 4

0

看一下位图的Image.Palette属性。

于 2009-04-28T13:33:37.077 回答
0

据我所知,.NET 不支持 ICC 颜色配置文件,因此,例如,如果您打开使用 Adob​​eRGB 颜色配置文件的图像,与打开相同图像相比,颜色会显得更暗淡且更“灰色”文件在 Photoshop 或其他颜色配置文件感知软件中。

这篇文章讨论了一些颜色配置文件问题;你可能会在那里找到一些有趣的东西。

于 2009-04-28T13:39:52.133 回答
0

GetPixel 和 SetPixel 确实很慢。如果要对单个像素进行操作,请考虑使用FastBitmap。它允许快速着色像素。使用这个不安全的位图将大大提高您的速度。

于 2009-04-28T13:44:49.733 回答
0

我解决了这个问题,看看如何。我在某处读到 GDI+ 返回 BGR 值而不是 RGB。所以我颠倒了顺序,一切都很好。但它有点慢。

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

       Rectangle rect = new Rectangle(0, 0, Img_Width, Img_Height);

       //locking the bitmap on memory
       BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, format);
       Marshal.Copy(rawPixel, 0, bmpData.Scan0, rawPixel.Length);

       int stride = bmpData.Stride;
       System.IntPtr Scan0 = bmpData.Scan0;

       unsafe
       {
           byte* p = (byte*)(void*)Scan0;
           int nOffset = stride - bmp.Width * SAMPLES_PER_PIXEL ;
           byte red, green, blue;

           for (int y = 0; y < bmp.Height; ++y)
            {
                for (int x = 0; x < bmp.Width; ++x)
                {
                    blue = p[0];
                    green = p[1];
                    red = p[2];
                    p[0] = red;
                    p[1] = green;
                    p[2] = blue;
                    p += 3;
                }
                p += nOffset;
            }
        }

        ////unlockimg the bitmap
        bmp.UnlockBits(bmpData);

谢谢

任何人都可以拥有比这更快的代码吗?

于 2009-04-29T10:33:11.807 回答