picture控件显示图像不正确

penghuahuijuan 2016-11-11 11:08:42
我想将一幅bmp图像显示在picture控件上,显示结果不正确,实在没检查出来错误;
我将图像单独保存确实正确的!!!!
程序如下:
位图信息头:
//采用的相机为300万;
m_iWidth = 2048;
m_iHeight = 1536;

m_nBmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_nBmpInfo.bmiHeader.biWidth = m_iWidth;
m_nBmpInfo.bmiHeader.biHeight = m_iHeight;
m_nBmpInfo.bmiHeader.biCompression = BI_RGB;
m_nBmpInfo.bmiHeader.biBitCount = 24;
m_nBmpInfo.bmiHeader.biClrUsed = 0;
m_nBmpInfo.bmiHeader.biClrImportant = 0;
m_nBmpInfo.bmiHeader.biSizeImage = m_iWidth*m_iHeight*3;
m_nBmpInfo.bmiHeader.biPlanes = 1;
显示图像:
//先绘制初始采集的图像;
CDC *pDC = m_pResultVideoWnd->GetDC();
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, m_ResultVideoRect.Width(), m_ResultVideoRect.Height());
CBitmap *pOldBmp = MemDC.SelectObject(&bmp);

StretchDIBits(MemDC.GetSafeHdc(),0, 0, m_ResultVideoRect.Width(), m_ResultVideoRect.Height(), 0, 0, bmpInfo.bmiHeader.biWidth,
bmpInfo.bmiHeader.biHeight, VideoData, &bmpInfo, DIB_RGB_COLORS,SRCCOPY);
pDC->BitBlt(0, 0, m_ResultVideoRect.Width(), m_ResultVideoRect.Height(), &MemDC, 0, 0, SRCCOPY);

源图像:

显示结果:

这是什么原因呢??谢谢大家??
以前我用一样的程序,显示是正确的啊!!!是不是图像太大,采样的原因呢???
...全文
184 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-11-12
  • 打赏
  • 举报
回复
换GDI+试试看。
赵4老师 2016-11-12
  • 打赏
  • 举报
回复
如果还是不对,试试用PS将图片文件转为jpg格式再转回bmp格式,另存为别的文件名,然后读刚才另存为的文件试试。
penghuahuijuan 2016-11-12
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
在桌面上点鼠标右键、选图形属性、……、颜色深度:32位
怎么在桌面设置??不理解!!! 和mfc有关系?? 我把工程传上来了,麻烦老师帮忙看看。 地址: http://download.csdn.net/detail/u014260892/9680850
赵4老师 2016-11-12
  • 打赏
  • 举报
回复
在桌面上点鼠标右键、选图形属性、……、颜色深度:32位
penghuahuijuan 2016-11-12
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
当前显示设置不是32位真彩色。我猜。
图像是24位的啊!为什么设置,在哪里设置呢??
penghuahuijuan 2016-11-12
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
当前显示设置不是32位真彩色。我猜。
赵老师,这个在哪里设置呢
赵4老师 2016-11-12
  • 打赏
  • 举报
回复
当前显示设置不是32位真彩色。我猜。
schlafenhamster 2016-11-12
  • 打赏
  • 举报
回复
应该是 // CDC* pDC = GetDC(); CDC MemDC; MemDC.CreateCompatibleDC(pDC); CBitmap bmp; bmp.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height()); CBitmap *pOldBmp = MemDC.SelectObject(&bmp); MemDC.SetStretchBltMode(HALFTONE); SetBrushOrgEx(MemDC.GetSafeHdc(),0,0,NULL); StretchDIBits(MemDC.GetSafeHdc(),0,0,rect.Width(),rect.Height(), 0,0,bmpInfoHdr.biWidth,bmpInfoHdr.biHeight, tmp_buf,(BITMAPINFO*)&bmpInfoHdr,DIB_RGB_COLORS,SRCCOPY);
penghuahuijuan 2016-11-12
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
如果还是不对,试试用PS将图片文件转为jpg格式再转回bmp格式,另存为别的文件名,然后读刚才另存为的文件试试。
赵老师,后来发现应该是兼容位图的原因,我直接用StretchDIBits显示正确; 如下: StretchDIBits(pDC->GetSafeHdc(),0, 0, m_ResultVideoRect.Width(), m_ResultVideoRect.Height(), 0, 0, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, VideoData, &bmpInfo, DIB_RGB_COLORS,SRCCOPY);
schlafenhamster 2016-11-12
  • 打赏
  • 举报
回复
StretchDIBits The StretchDIBits function copies the color data for a rectangle of pixels in a device-independent bitmap (DIB) to the specified destination rectangle. If the destination rectangle is larger than the source rectangle, this function stretches the rows and columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, this function compresses the rows and columns by using the specified raster operation. 不要用他 伸缩 试试 bitblt 加 滚动条

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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