﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-《深入解析ATL》第二版中文版上市-随笔分类-Graphics</title><link>http://www.cppblog.com/TechLab/category/170.html</link><description>有问题请到CSDN-&gt;VC/MFC讨论</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 15:08:17 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 15:08:17 GMT</pubDate><ttl>60</ttl><item><title>GDI转BMP为WMF</title><link>http://www.cppblog.com/TechLab/archive/2006/01/12/2640.html</link><dc:creator>TechLab</dc:creator><author>TechLab</author><pubDate>Thu, 12 Jan 2006 02:25:00 GMT</pubDate><guid>http://www.cppblog.com/TechLab/archive/2006/01/12/2640.html</guid><wfw:comment>http://www.cppblog.com/TechLab/comments/2640.html</wfw:comment><comments>http://www.cppblog.com/TechLab/archive/2006/01/12/2640.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/TechLab/comments/commentRss/2640.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/TechLab/services/trackbacks/2640.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;这是CSDN上一个网友的问题<BR>HDC hdc = CreateMetaFile("c:\\test.wmf");&nbsp;&nbsp;&nbsp;//测试的目标文件路径<BR>&nbsp;HBITMAP hbmp = (HBITMAP)::LoadImage(NULL,"c:\\te12.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);<BR>&nbsp;CDC memdc;<BR>&nbsp;memdc.CreateCompatibleDC(GetDC());<BR>&nbsp;HBITMAP hold = (HBITMAP)memdc.SelectObject(hbmp);<BR>&nbsp;BITMAP bmp;<BR>&nbsp;::GetObject(hbmp,sizeof(bmp),&amp;bmp);<BR>&nbsp;if(hbmp != NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;BitBlt(hdc,0,0,bmp.bmWidth,bmp.bmHeight,memdc.m_hDC,0,0,SRCCOPY);<BR>&nbsp;}<BR>&nbsp;memdc.SelectObject(hold);<BR>&nbsp;memdc.DeleteDC();<BR>&nbsp;CloseMetaFile(hdc);<img src ="http://www.cppblog.com/TechLab/aggbug/2640.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/TechLab/" target="_blank">TechLab</a> 2006-01-12 10:25 <a href="http://www.cppblog.com/TechLab/archive/2006/01/12/2640.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用IPicture接口加载、显示图片</title><link>http://www.cppblog.com/TechLab/archive/2005/10/20/758.html</link><dc:creator>TechLab</dc:creator><author>TechLab</author><pubDate>Thu, 20 Oct 2005 06:50:00 GMT</pubDate><guid>http://www.cppblog.com/TechLab/archive/2005/10/20/758.html</guid><wfw:comment>http://www.cppblog.com/TechLab/comments/758.html</wfw:comment><comments>http://www.cppblog.com/TechLab/archive/2005/10/20/758.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/TechLab/comments/commentRss/758.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/TechLab/services/trackbacks/758.html</trackback:ping><description><![CDATA[<P>IPicture接口管理一个图片对象和它的属性。图片对象提供对Bitmap Icon Metafile的语言不相关的抽象支持。图像对象的主要接口是IPicture和IPictureDisp。IPictureDisp从IDispatch继承，提供了通过自动化访问图片属性的能力。图片对象可通过OleCreatePictureIndirect创建。关于IPicture支持的其他接口和方法可以看MSDN，一般创建图片对象可以用OleLoadPicture函数，它简化了基于流内容创建图片对象。下面的代码中有两个未定义的变量是FilePath和hDC。<BR>//FilePath是从外部传入的图片路径<BR>//打开文件<BR>HANDLE hFile = CreateFile(FilePath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);<BR>_ASSERTE(INVALID_HANDLE_VALUE != hFile);<BR>//取文件大小<BR>DWORD dwFileSize = GetFileSize(hFile, NULL);<BR>_ASSERTE(-1 != dwFileSize);<BR>LPVOID pvData = NULL;<BR>//分配内存，准备读入图片文件的数据<BR>//GlobalAlloc从堆分配指定字节的内存区域<BR>HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);<BR>_ASSERTE(NULL != hGlobal);<BR>//GlobalLock函数锁住一个全局的内存对象同时返回一个指向对象首字节的指针 <BR>pvData = GlobalLock(hGlobal);<BR>_ASSERTE(NULL != pvData);<BR>DWORD dwBytesRead = 0;<BR>//读取文件的数据到分配的全局内存<BR>BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);<BR>_ASSERTE(FALSE != bRead);<BR>GlobalUnlock(hGlobal);<BR>CloseHandle(hFile);</P>
<P>//到此，我们已经把文件的数据读到了内存当中</P>
<P>LPSTREAM pstm = NULL;<BR>//从全局内存创建IStream接口指针<BR>HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);<BR>_ASSERTE(SUCCEEDED(hr) && pstm);<BR>//根据图片文件创建IPicture接口指针<BR>hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);<BR>_ASSERTE(SUCCEEDED(hr) && gpPicture); <BR>pstm->Release();</P>
<P>//至此，IPicture接口建立好，下面开始画图片<BR>//hDC是外部传入的画图设备<BR>long hmWidth;<BR>long hmHeight;<BR>gpPicture->get_Width(&hmWidth);<BR>gpPicture->get_Height(&hmHeight);<BR>//转换himetric距离为pixels距离，1英寸=25.4毫米<BR>int nWidth = MulDiv(hmWidth, GetDeviceCaps(hDC, LOGPIXELSX), 2540);<BR>int nHeight = MulDiv(hmHeight, GetDeviceCaps(hDC, LOGPIXELSY), 2540);<BR>RECT rc;<BR>GetClientRect(hWnd, &rc);<BR>//IPicture::Render显示图片<BR>gpPicture->Render(hDC, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc);</P><img src ="http://www.cppblog.com/TechLab/aggbug/758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/TechLab/" target="_blank">TechLab</a> 2005-10-20 14:50 <a href="http://www.cppblog.com/TechLab/archive/2005/10/20/758.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>