请教下libjpeg读取RGB的问题

chp845 2012-08-29 09:00:07
#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
int nHeight = cinfo.image_height;  
int nWidth = cinfo.image_width;
int nBits = cinfo.num_components;

unsigned char * pRGB = new unsigned char[cinfo.image_width *cinfo.image_height * cinfo.num_components];
jpeg_start_decompress(&cinfo);
JSAMPROW row_pointer[1];
while(cinfo.output_scanline < cinfo.output_height)
{
row_pointer[0]=&pRGB[cinfo.output_scanline*cinfo.image_width*cinfo.num_components];
jpeg_read_scanlines(&cinfo, row_pointer, 1);
}

int nWidthEx = WIDTHBYTES( 24 * nWidth);
int nLineTailDest = nWidthEx - 3 * nWidth;
unsigned char * pRGBA = new unsigned char[nHeight * nWidthEx];
memset(pRGBA, 0, nHeight * nWidthEx);

BYTE *p1 = (BYTE*)pRGBA;
for (unsigned int i = 0; i < nHeight; i++)
{
unsigned char * pStart = pRGB + i * nWidth * cinfo.num_components; //num_components等于3
for (unsigned int j = 0; j < nWidth; j++)
{
UINT b = *pStart++;
UINT g = *pStart++;
UINT r = *pStart++;
*p1++ = r;
*p1++ = g;
*p1++ = b;
}
p1 += nLineTailDest;
}


请问下,我用libjpeg读取jpeg(24位)图片,读取出位图RGB的数据,
我使用:
bitmap.CreateBitmap(GetImageW(pData), GetImageH(pData), 1, 24, GetImageBuf(pData));
BITMAP bim;
bitmap.GetBitmap(&bim);
但是在屏幕上面无法显示,但是bim又可以获取到值,请教下这是怎么回事呀?
...全文
243 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
panyufeng000 2012-12-12
  • 打赏
  • 举报
回复
引用 楼主 chp845 的回复:
#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4) C/C++ code?123456789101112131415161718192021222324252627282930313233int nHeight = cinfo.image_height; int nWidth = cinfo.image_……
内存对齐不正确!
chp845 2012-08-30
  • 打赏
  • 举报
回复
有人可以帮助解答下吗?

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧