怎样在MFC中读取一幅图片并显示在对话框里面
展开全部
对话框类加一个存图像路径的变量
用来选择和打开图像
处理图像的部分写在“开始”按键的响应函数里
关于显示:你一个MFC对话框程序想显示图像在那啊?
如果只要直接画上去的话就重载OnPaint写代码
用来选择和打开图像
处理图像的部分写在“开始”按键的响应函数里
关于显示:你一个MFC对话框程序想显示图像在那啊?
如果只要直接画上去的话就重载OnPaint写代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-11-08
展开全部
{
typedef int (WINAPI ICEPUB_DISPIMG)(HWND hWnd,char *strImgFilename,int x,int y);
ICEPUB_DISPIMG *icePub_dispImg = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_dispImg = (ICEPUB_DISPIMG *)GetProcAddress(hDLLDrv, "icePub_dispImg");
}
if(icePub_dispImg != NULL)
icePub_dispImg(m_hWnd,"b.png",10,10);
// icePub_dispImg(m_ctrlText.m_hWnd,"b.jpg",0,0);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
typedef int (WINAPI ICEPUB_DISPIMG)(HWND hWnd,char *strImgFilename,int x,int y);
ICEPUB_DISPIMG *icePub_dispImg = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_dispImg = (ICEPUB_DISPIMG *)GetProcAddress(hDLLDrv, "icePub_dispImg");
}
if(icePub_dispImg != NULL)
icePub_dispImg(m_hWnd,"b.png",10,10);
// icePub_dispImg(m_ctrlText.m_hWnd,"b.jpg",0,0);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个挺麻烦的,我有源码和程序,可以编译可以运行,要的话你给我发个邮件980350398@qq.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/****************************************************************************
CDrawBitmap封装了一些画图片的函数。
调用如下:
CDrawBitmap g_bmp1("D:\\My Documents\\My Pictures\\风景图片\\4244123431.bmp");
g_bmp1.Draw(m_hWnd);
CDrawBitmap g_bmp2("D:\\My Documents\\My Pictures\\风景图片\\plane.bmp");
g_bmp2.DrawTransparent(m_hWnd);
CDrawBitmap g_bmp3("D:\\My Documents\\My Pictures\\风景图片\\jzg2.bmp");
g_bmp3.DrawTransparent(m_hWnd);
****************************************************************************/
//使用TransparentBlt需要添加 #pragma comment(lib,"msimg32.lib")
#pragma comment(lib,"msimg32.lib")
class CDrawBitmap
{
private:
HBITMAP m_bitmap;
int m_bitmap_cx;
int m_bitmap_cy;
public:
CDrawBitmap() {}
CDrawBitmap(TCHAR * PicturePath) { LoadPicture(PicturePath); }
CDrawBitmap(WORD ResourceID) { LoadResource(ResourceID); }
~CDrawBitmap() { ::DeleteObject(m_bitmap);}
bool LoadPicture(TCHAR * PicturePath)
{
m_bitmap=(HBITMAP)LoadImage(NULL, //应用程序实例
PicturePath, //路径
IMAGE_BITMAP,
0, //如果不置0,则此参数指定m_bitmap的宽(位图被拉伸)
0, //如果不置0,则此参数指定m_bitmap的高(位图被拉伸)
LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
if (!m_bitmap)
return false;
BITMAP bmp;
GetObject(m_bitmap,sizeof(BITMAP),(LPSTR)&bmp);
m_bitmap_cx=bmp.bmWidth;
m_bitmap_cy=bmp.bmHeight;
return true;
}
bool LoadResource(WORD ResourceID)
{
m_bitmap=LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE (ResourceID) );
if (!m_bitmap)
return false;
BITMAP bmp;
GetObject(m_bitmap,sizeof(BITMAP),(LPSTR)&bmp);
m_bitmap_cx=bmp.bmWidth;
m_bitmap_cy=bmp.bmHeight;
return true;
}
void Draw(HWND hWnd=NULL,int x=0,int y=0,int width=100,int height=100)
{
HDC hScrDC=GetDC(hWnd); //创建屏幕DC
Draw(hScrDC,x,y,width,height);
::ReleaseDC(hWnd,hScrDC) ; //释放屏幕DC
}
void Draw(HDC hScrDC,int x=0,int y=0,int width=100,int height=100)
{
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
::SelectObject(hMemDC,m_bitmap); //把位图选进内存DC
BitBlt(hScrDC,x,y,width,height,hMemDC,0,0,SRCCOPY); //内存DC映射到屏幕DC
::DeleteDC(hMemDC) ; //删除内存DC
}
void DrawTransparent(HWND hWnd=NULL,int x=0,int y=0)
{
HDC hScrDC=GetDC(hWnd); //创建屏幕DC
DrawTransparent(hScrDC,x,y);
::ReleaseDC(hWnd,hScrDC) ; //释放屏幕DC
}
//不进行拉伸处理,如需要,请自行修改代码TransparentBlt中的参数
//使用TransparentBlt需要添加 #pragma comment(lib,"msimg32.lib")
void DrawTransparent(HDC hScrDC,int x=0,int y=0,UINT crTransparent=RGB(255,255,255))
{
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
::SelectObject(hMemDC,m_bitmap); //把位图选进内存DC
::TransparentBlt(hScrDC,x,y,m_bitmap_cx,m_bitmap_cy,hMemDC,0,0,m_bitmap_cx,m_bitmap_cy,crTransparent);
::DeleteDC(hMemDC) ; //删除内存DC
}
void DrawStretch(HWND hWnd=NULL,int x=0,int y=0,int width=100,int height=100)
{
HDC hScrDC=GetDC(hWnd); //创建屏幕DC
DrawStretch(hScrDC,x,y,width,height);
::ReleaseDC(hWnd,hScrDC) ; //释放屏幕DC
}
void DrawStretch(HDC hScrDC=NULL,int x=0,int y=0,int width=100,int height=100)
{
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
::SelectObject(hMemDC,m_bitmap); //把位图选进内存DC
SetStretchBltMode(hScrDC,COLORONCOLOR); //一定要先调用这个
StretchBlt(hScrDC,x,y,width,height,hMemDC,0,0,m_bitmap_cx,m_bitmap_cy,SRCCOPY); //内存DC映射到屏幕DC
::DeleteDC(hMemDC) ; //删除内存DC
}
};
CDrawBitmap封装了一些画图片的函数。
调用如下:
CDrawBitmap g_bmp1("D:\\My Documents\\My Pictures\\风景图片\\4244123431.bmp");
g_bmp1.Draw(m_hWnd);
CDrawBitmap g_bmp2("D:\\My Documents\\My Pictures\\风景图片\\plane.bmp");
g_bmp2.DrawTransparent(m_hWnd);
CDrawBitmap g_bmp3("D:\\My Documents\\My Pictures\\风景图片\\jzg2.bmp");
g_bmp3.DrawTransparent(m_hWnd);
****************************************************************************/
//使用TransparentBlt需要添加 #pragma comment(lib,"msimg32.lib")
#pragma comment(lib,"msimg32.lib")
class CDrawBitmap
{
private:
HBITMAP m_bitmap;
int m_bitmap_cx;
int m_bitmap_cy;
public:
CDrawBitmap() {}
CDrawBitmap(TCHAR * PicturePath) { LoadPicture(PicturePath); }
CDrawBitmap(WORD ResourceID) { LoadResource(ResourceID); }
~CDrawBitmap() { ::DeleteObject(m_bitmap);}
bool LoadPicture(TCHAR * PicturePath)
{
m_bitmap=(HBITMAP)LoadImage(NULL, //应用程序实例
PicturePath, //路径
IMAGE_BITMAP,
0, //如果不置0,则此参数指定m_bitmap的宽(位图被拉伸)
0, //如果不置0,则此参数指定m_bitmap的高(位图被拉伸)
LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
if (!m_bitmap)
return false;
BITMAP bmp;
GetObject(m_bitmap,sizeof(BITMAP),(LPSTR)&bmp);
m_bitmap_cx=bmp.bmWidth;
m_bitmap_cy=bmp.bmHeight;
return true;
}
bool LoadResource(WORD ResourceID)
{
m_bitmap=LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE (ResourceID) );
if (!m_bitmap)
return false;
BITMAP bmp;
GetObject(m_bitmap,sizeof(BITMAP),(LPSTR)&bmp);
m_bitmap_cx=bmp.bmWidth;
m_bitmap_cy=bmp.bmHeight;
return true;
}
void Draw(HWND hWnd=NULL,int x=0,int y=0,int width=100,int height=100)
{
HDC hScrDC=GetDC(hWnd); //创建屏幕DC
Draw(hScrDC,x,y,width,height);
::ReleaseDC(hWnd,hScrDC) ; //释放屏幕DC
}
void Draw(HDC hScrDC,int x=0,int y=0,int width=100,int height=100)
{
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
::SelectObject(hMemDC,m_bitmap); //把位图选进内存DC
BitBlt(hScrDC,x,y,width,height,hMemDC,0,0,SRCCOPY); //内存DC映射到屏幕DC
::DeleteDC(hMemDC) ; //删除内存DC
}
void DrawTransparent(HWND hWnd=NULL,int x=0,int y=0)
{
HDC hScrDC=GetDC(hWnd); //创建屏幕DC
DrawTransparent(hScrDC,x,y);
::ReleaseDC(hWnd,hScrDC) ; //释放屏幕DC
}
//不进行拉伸处理,如需要,请自行修改代码TransparentBlt中的参数
//使用TransparentBlt需要添加 #pragma comment(lib,"msimg32.lib")
void DrawTransparent(HDC hScrDC,int x=0,int y=0,UINT crTransparent=RGB(255,255,255))
{
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
::SelectObject(hMemDC,m_bitmap); //把位图选进内存DC
::TransparentBlt(hScrDC,x,y,m_bitmap_cx,m_bitmap_cy,hMemDC,0,0,m_bitmap_cx,m_bitmap_cy,crTransparent);
::DeleteDC(hMemDC) ; //删除内存DC
}
void DrawStretch(HWND hWnd=NULL,int x=0,int y=0,int width=100,int height=100)
{
HDC hScrDC=GetDC(hWnd); //创建屏幕DC
DrawStretch(hScrDC,x,y,width,height);
::ReleaseDC(hWnd,hScrDC) ; //释放屏幕DC
}
void DrawStretch(HDC hScrDC=NULL,int x=0,int y=0,int width=100,int height=100)
{
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
::SelectObject(hMemDC,m_bitmap); //把位图选进内存DC
SetStretchBltMode(hScrDC,COLORONCOLOR); //一定要先调用这个
StretchBlt(hScrDC,x,y,width,height,hMemDC,0,0,m_bitmap_cx,m_bitmap_cy,SRCCOPY); //内存DC映射到屏幕DC
::DeleteDC(hMemDC) ; //删除内存DC
}
};
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询