IPicture::Render参数详解
2016-04-14 14:39
267 查看
在C++中读取图片到屏幕上,首先需要加入这两个头文件
#include <ocidl.h>
#include <olectl.h>
关于render在MSDN中是这样写的
HRESULT Render(
HDC hdc, //Handle of device context on which to render the image
long x, //Horizontal position of image in hdc
long y, //Vertical position of image in hdc
long cx, //Horizontal dimension of destination rectangle
long cy, //Vertical dimension of destination rectangle
OLE_XPOS_HIMETRIC xSrc, //Horizontal offset in source picture
OLE_YPOS_HIMETRIC ySrc, //Vertical offset in source picture
OLE_XSIZE_HIMETRIC cxSrc, //Amount to copy horizontally in source picture
OLE_YSIZE_HIMETRIC cySrc, //Amount to copy vertically in source picture
LPCRECT prcWBounds //Pointer to position of destination for a metafile hdc
);
hdc 是设备环境句柄,
x、y是图片在设备中显示的坐标,
cx、cy是要显示图片的矩形的长度和宽度,注意,用IPicture::get_Width和IPicture::get_Height的得到的数据并不适用于此处,而是要除以2540
比如: pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
//转换hmWidth和hmHeight为pixels距离,1英寸=25.4毫米
int nWidth = MulDiv(hmWidth,GetDeviceCaps(hDC_Temp,LOGPIXELSX),2540);
int nHeight = MulDiv(hmHeight,GetDeviceCaps(hDC_Temp,LOGPIXELSY),2540);
xSrc,ySrc分别是在源图像上的水平偏移和在源图像上的垂直偏移;
cxSrc是在源图像上水平拷贝的数量,cySrc是在源图像上垂直拷贝的数量;
prcWBounds是指向目标图元设备环境句柄的指针,一般为NULL。
为什么用render函数的时候都是Render(hdc, xPos, yPos, width, height, 0, srcHeight,srcWidth,-srcHeight);
原因是这样的:这个和位图的格式有关,位图文件中最开始的像素数据不是图像左上角这个像素,而是图像中最后一行最左边像素点的数据。所以左顶点是(0,hmHeight)
hmWidth表示宽度,-hmHeight是负数,表示从最后一行读取,并显示在第一行。
#include <ocidl.h>
#include <olectl.h>
关于render在MSDN中是这样写的
HRESULT Render(
HDC hdc, //Handle of device context on which to render the image
long x, //Horizontal position of image in hdc
long y, //Vertical position of image in hdc
long cx, //Horizontal dimension of destination rectangle
long cy, //Vertical dimension of destination rectangle
OLE_XPOS_HIMETRIC xSrc, //Horizontal offset in source picture
OLE_YPOS_HIMETRIC ySrc, //Vertical offset in source picture
OLE_XSIZE_HIMETRIC cxSrc, //Amount to copy horizontally in source picture
OLE_YSIZE_HIMETRIC cySrc, //Amount to copy vertically in source picture
LPCRECT prcWBounds //Pointer to position of destination for a metafile hdc
);
hdc 是设备环境句柄,
x、y是图片在设备中显示的坐标,
cx、cy是要显示图片的矩形的长度和宽度,注意,用IPicture::get_Width和IPicture::get_Height的得到的数据并不适用于此处,而是要除以2540
比如: pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
//转换hmWidth和hmHeight为pixels距离,1英寸=25.4毫米
int nWidth = MulDiv(hmWidth,GetDeviceCaps(hDC_Temp,LOGPIXELSX),2540);
int nHeight = MulDiv(hmHeight,GetDeviceCaps(hDC_Temp,LOGPIXELSY),2540);
xSrc,ySrc分别是在源图像上的水平偏移和在源图像上的垂直偏移;
cxSrc是在源图像上水平拷贝的数量,cySrc是在源图像上垂直拷贝的数量;
prcWBounds是指向目标图元设备环境句柄的指针,一般为NULL。
为什么用render函数的时候都是Render(hdc, xPos, yPos, width, height, 0, srcHeight,srcWidth,-srcHeight);
原因是这样的:这个和位图的格式有关,位图文件中最开始的像素数据不是图像左上角这个像素,而是图像中最后一行最左边像素点的数据。所以左顶点是(0,hmHeight)
hmWidth表示宽度,-hmHeight是负数,表示从最后一行读取,并显示在第一行。
相关文章推荐
- C Primer Plus(第五版) 第十四章 课后习题 4
- Tips:无法正常卸载AppFabric 1.1的RU5 KB补丁
- Intellij Idea get/set方法快捷键
- ScrollView起始位置不再最顶端的解决方案
- 一段文字内有不同颜色字体交叉显示
- 错误: ARC forbids explicit message send of 'release'
- 关于ScrollView中嵌套listview焦点滑动问题 解决
- 进入BIOS SHELL DUMP 命令
- Android 自定义View高级特效,神奇的贝塞尔曲线
- Ubuntu系统操作笔记
- JavaScirpt之JQuery库入门篇
- VS中修改.net版本
- python mongoengine
- Android中Listview实现分页加载效果OnScrollListener
- 虚拟机Ubuntu Server(宿主Win7)ftp服务的安装与启动
- windows下使用命令行运行PHP
- Ubuntu ctrl+alt+F1~F6黑屏
- FTP客户端(利用sun.net.ftp.FtpClient实现)
- linux 查看文件系统类型
- Linux进程间通信——使用共享内存