如何修复(改变).jpg颜色GDI +到PixelFormat24bppRGB? [英] how to fix(change) .jpg colors GDI+ to PixelFormat24bppRGB ?

查看:796
本文介绍了如何修复(改变).jpg颜色GDI +到PixelFormat24bppRGB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下文章中:
查找包含在另一个位图中的位图

In the following article:
Finding a Bitmap contained inside another Bitmap

There is GDI+ method to load bitmap before use of LockBits funtion. We ant to use only PixelFormat24bppRGB because then we want LockBits to determine pixels of bitmap. It works pretty well, when we use .bmp image as source. But when I try to use another format, this is not working at all.

I tried to load .jpg with GDI+ and then to make a clone with only PixelFormat24bppRGB.
With no success.

Gdiplus::Bitmap* bm = new Bitmap(L"test.jpg");
Gdiplus::Bitmap* bigBmp = bm->Clone(0, 0, bm->GetWidth(), bm->GetHeight(), PixelFormat24bppRGB);
Gdiplus::BitmapData* bigbitmapData = new BitmapData;
Gdiplus::Rect bigRect(0, 0, bigBmp->GetWidth(), bigBmp->GetHeight());
bigBmp->LockBits(&bigRect, ImageLockModeRead, PixelFormat24bppRGB, bigbitmapData);


jpg的位图已正确加载,因为我获得了正确的宽度和高度.

当我在上面的代码中使用时:


the bitmap from jpg is loaded correctly because I got correct width and height.

When I use in the above code:

Gdiplus::Bitmap* bm = new Bitmap(L"test.bmp");


(在.bmp中,我测试了24位颜色以及16位和8位两种颜色)一切正常.

我猜问题是因为.jpg中的颜色数字

如何修复PixelFormat24bppRGB的.jpg?任何的想法?请.


(where .bmp I tested both 24-bits colors and 16 and 8-bits) everything is working fine.

I guess the problem is becasue of colors number in .jpg

How to fix .jpg for PixelFormat24bppRGB? Any idea? please.

推荐答案

更正:

此问题仅适用于JPEG.

.bmp和.png和.tif文件格式都可以正常工作.

具有任何颜色格式.

.png 24位颜色以及减少到256种颜色都可以正常工作.

也许问题出在LockBits函数中,而不是在代码的下一部分中?

我们在其中计算像素亮度以在位图中找到.
(请参阅上面的文章)
correction:

this problem is for JPEG only.

both .bmp and .png and .tif file formats are working correctly.

with any colors format.

.png 24-bits colors and the reduced to 256 colors are working fine.

maybe the problem is not in LockBits function, but with the next part of code?

where we calculate pixels luminance to find inside the bitmap.
(see the above article)


这篇关于如何修复(改变).jpg颜色GDI +到PixelFormat24bppRGB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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