请问下用LIBJPEG读取出来的RGB,怎么可以直接显示出来呀?

chp845 2012-08-29 09:34:06
我用libjpeg读取出24位的jpeg的RGB
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);

//RGB 转化为BGR
for (int i = 0; i < nWidth * cinfo.num_components; i += cinfo.num_components)
{
unsigned char temp = row_pointer[0][i + 2];
row_pointer[0][i + 2] = row_pointer[0][i]; //RED
row_pointer[0][i] = temp; //BLUE
}
}

怎么我这样读取出来的BRG字节,转换为位图是空白,没有办法显示呀?
但是我在BRG加ALPHA = 0为32位的位图,却又可以正常显示,这是怎么回事呀,有人可以解答下吗?
...全文
253 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gloveing 2012-09-04
  • 打赏
  • 举报
回复
SetPixel
the_venus 2012-09-04
  • 打赏
  • 举报
回复
24位的位图进行4字节补齐代码是这样的:

int imageWidth,imageHeight,imageBitCount;
BYTE *pSrcData;//原始未对齐的数据
BYTE *pDestData;//对齐后的数据
...

int nLine,nScanLine;
PBYTE pSrc;
PBYTE pDest;
nLine = imageWidth * imageBitCount / 8;
nScanLine = (nLine %4)?(nLine + 4 - (nLine %4)):nLine;
pDestData = (BYTE*)malloc(nScanLine * imageHeight);
memset(pDest,0,(nScanLine * imageHeight));
pSrc = pSrcData;
pDest = pDestData;
for(int i=0;i<imageHeight;i++)
{
memcpy(pDestData,pSrcData,nLine);
pSrcData += nLine;
pDestData += nScanLine;
}

这样就对齐了
geansea 2012-08-29
  • 打赏
  • 举报
回复
生成的bmp没有4字节补齐?
chp845 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

引用 1 楼 的回复:

生成的bmp没有4字节补齐?


24位的bmp应该怎么进行4字节补齐呀!
[/Quote]
是不是只要被4整除即可!
chp845 2012-08-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

生成的bmp没有4字节补齐?
[/Quote]

24位的bmp应该怎么进行4字节补齐呀!

19,468

社区成员

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

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