加载图片
来源:互联网 发布:域名所有者查询 编辑:程序博客网 时间:2024/04/28 18:10
1.建立单文档工程
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/html/42e3cd0e-2413-494a-8be8-2952089e02d2.asp
/////////.bmp/////////
void CYXRMView::OnDraw(CDC* pDC)
{
CYXRMDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HBITMAP hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"River Sumida.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap m_bitmap;
m_bitmap.Attach(hBitmap);
BITMAP bm;
m_bitmap.GetBitmap(&bm);
CDC dcImage;
dcImage.CreateCompatibleDC(pDC);
dcImage.SelectObject(&m_bitmap);
CRect rect;
GetClientRect(rect);
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcImage,0,0,SRCCOPY);
}
/////////.jpg/////////
void CYXRMView::OnDraw(CDC* pDC)
{
CYXRMDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
IPicture *pPic;
IStream *pStm;
CRect rect;
CFileStatus fstatus;
CFile file;
LONG cb;
if (file.Open("11665_.jpg",CFile::modeRead)&&file.GetStatus("11665_.jpg",
fstatus)&&
((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
if ((pvData = GlobalLock(hGlobal)) != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
////////按窗口尺寸显示////////
CRect rect;
GetClientRect(&rect);
if(FAILED(pPic->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(),0,hmHeight,hmWidth,-hmHeight,NULL)))
AfxMessageBox("Failed To Render The picture!");
////////原大显示//////
/*CSize sz( hmWidth, hmHeight );
pDC->HIMETRICtoDP(&sz); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
if(FAILED(pPic->Render(pDC->m_hDC,0,0,sz.cx,sz.cy,0,hmHeight,hmWidth,-hmHeight,NULL)))
AfxMessageBox("Failed To Render The picture!"); */
pPic->Release();
}
else
AfxMessageBox("Error Loading Picture From Stream!");
}
}
}
else
AfxMessageBox("Can't Open Image File!");
}
- 加载图片
- 图片加载
- 图片加载
- 图片加载
- 图片加载
- 图片加载
- 加载图片
- 图片加载
- 图片加载
- 加载图片
- 图片加载
- 加载图片
- 图片加载
- 图片加载
- 图片加载
- 图片加载---预加载
- win32加载图片、加载声音
- 图片加载js--图片被动加载
- 男人必看得5个故事
- [转]Java视线论坛 阅读主题 - 面向对象的思维方法
- 系统的在技术上的构架
- 面向对象,服务器架构,设计模式探讨
- 数学和中国文学的比较
- 加载图片
- 我的主页http://520.xhu.cn
- 数据库连接池的问题
- 面试结束后应该说的那句话
- 我的第一篇BLOG
- Serious Engine分析
- 新建网站
- 自动改变CheckBoxList选择项目的背景颜色
- 在软件系统化门外游荡