如何在 C# 中的位图图像上应用 Color Lut
我正在打开不同类型的图像,例如(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() 方法。
I am opening different types of images like (8 and 16 bit) and they are (Monocrome, RGB ,palette color).
I have raw pixel data of these images.
I create bitmap like this for 8 bit images.
//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);
The problem is that when i draw that bmp image then it differs in color than original.
So is there any way to apply lut (lookup table) on that colored images.
i want any unsafe code because i tried getixel and setPixel and they are very slow.
I also dont want Image.fromSource() methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看一下位图的
Image.Palette
属性。Take a look at the bitmap's
Image.Palette
property.据我所知,.NET 不支持 ICC 颜色配置文件,因此,如果您打开使用 AdobeRGB 颜色配置文件的图像,则颜色会比打开同一图像时显得更暗淡且更“灰”例如,在 Photoshop 或其他支持颜色配置文件的软件中保存文件。
这篇文章讨论了一些颜色配置文件问题; 你可能会在那里找到一些感兴趣的东西。
As far as I know, .NET does not support ICC color profiles, so if you for instance open an image that is using the AdobeRGB color profile, the colours will appear a bit duller and more "greyish" than if you open the same image file in, say, Photoshop or another color-profile-aware software.
This post discusses some color profile issues; you may find something of interest there.
GetPixel和SetPixel确实很慢。 如果您想对单个像素进行操作,请考虑使用 FastBitmap。 它允许快速为像素着色。 使用这个不安全的位图将大大提高你的速度。
GetPixel and SetPixel are indeed very slow. If you want to do operations on single pixels, consider using a FastBitmap. It allows to quickly color pixels. Using this unsafe bitmap will greatly improve your speed.
我解决了这个问题看看如何。
我在某处读到 GDI+ 返回 BGR 值而不是 RGB。
所以我颠倒了顺序,一切都很好。
但它有点慢。
谢谢
有人可以有比这更快的代码吗?
i solved this problem see how.
Somewhere i read that GDI+ return BGR value not the RGB.
So i reverse the order and amazing everything fine.
But it is little bit slow.
thanks
Can anybody is having some faster code than that.