怎么在一个基于对话框的程序中显示图像?

Ryan1005 2005-03-14 07:43:19
我已经把图像数据读入到内存,但是调用StretchDIBits却不能将图像显示在对话框上面,为什么?
...全文
106 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyjzy5 2005-03-23
  • 打赏
  • 举报
回复
“调用StretchDIBits却不能将图像显示在对话框上面,为什么?”

这样情况原因多了。既然你已经把图像数据读入到内存,那你就看看参数是不是正确了。
int StretchDIBits(
HDC hdc, // handle to device context
int XDest, // x-coordinate of upper-left corner of dest. rectangle
int YDest, // y-coordinate of upper-left corner of dest. rectangle
int nDestWidth, // width of destination rectangle
int nDestHeight, // height of destination rectangle
int XSrc, // x-coordinate of upper-left corner of source rectangle
int YSrc, // y-coordinate of upper-left corner of source rectangle
int nSrcWidth, // width of source rectangle
int nSrcHeight, // height of source rectangle
CONST VOID *lpBits, // address of bitmap bits
CONST BITMAPINFO *lpBitsInfo, // address of bitmap data
UINT iUsage, // usage flags
DWORD dwRop // raster operation code
);
或者你把相应代码贴出来看看。
lazio88 2005-03-18
  • 打赏
  • 举报
回复
BOOL DisplayBMP(BYTE *pBuffer,int nIDC_DISPLAY,int nBMPWidth,int nBMPHeight,BITMAPINFOHEADER *pbih)
{
if(pBuffer == NULL)
return FALSE;
HWND hwnd = NULL;
CWnd *pwnd = GetDlgItem(nIDC_DISPLAY);
hwnd = pwnd->m_hWnd;

RECT rc;
::GetWindowRect( hwnd, &rc );

int nrcWidth = rc.right - rc.left;
int nrcHeight = rc.bottom - rc.top;

HDC hdc = ::GetDC( hwnd );
PAINTSTRUCT ps;
::BeginPaint(hwnd, &ps);

SetStretchBltMode(hdc, COLORONCOLOR);
int nVal = StretchDIBits(
hdc, 0, 0,
nrcWidth, nrcHeight,
0, 0, nBMPWidth, nBMPHeight,
pBuffer,
(BITMAPINFO*)pbih,
DIB_RGB_COLORS,
SRCCOPY );

::EndPaint(hwnd, &ps);
::ReleaseDC( hwnd, hdc );
if(nVal)
return TRUE;
else
return FALSE;
}
直接调用该函数即可,其中pBuffer是指向内存数据指针(不包括文件头信息),nIDC_DISPLAY是对话框上的控件,位图显示在上面。
wshcdr 2005-03-14
  • 打赏
  • 举报
回复
GZ
Ryan1005 2005-03-14
  • 打赏
  • 举报
回复
我在内存中的图像数据是RGBRGB。。。的序列,又该怎么做?
bobob 2005-03-14
  • 打赏
  • 举报
回复

SelectObject(hDC,hBitmap);

hDC是对话框的句柄,hBitmap是位图句柄
Ryan1005 2005-03-14
  • 打赏
  • 举报
回复
能不能给个例子?
bobob 2005-03-14
  • 打赏
  • 举报
回复
直接把位图句并选入dc就可以

19,469

社区成员

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

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