Win32 库函数学习(一)
来源:互联网 发布:mac u盘装win7 编辑:程序博客网 时间:2024/05/21 11:18
BOOL BitBlt(
HDC hdcDest, // handle to destination device context
int nXDest, // x-coordinate of destination rectangle's upper-left
// corner
int nYDest, // y-coordinate of destination rectangle's upper-left
// corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source device context
int nXSrc, // x-coordinate of source rectangle's upper-left
// corner
int nYSrc, // y-coordinate of source rectangle's upper-left
// corner
DWORD dwRop // raster operation code
);
Bitblt(读作「bit blit」)代表「位块传输(bit-block transfer)」。BLT起源于一条汇编语言指令,该指令在DEC PDP-10上用来传输内存块。术语「bitblt」第一次用在图像上与Xerox Palo Alto Research Center(PARC)设计的SmallTalk系统有关。在SmallTalk中,所有的图形输出操作都使用bitblt。程序写作者有时将blt用作动词,例如:「Then I wrote some code to blt the happy face to the screen and play a wave file.」
BitBlt函数移动的是像素,或者(更明确地)是一个位映像图块。您将看到,术语「传输(transfer)」与BitBlt函数不尽相同。此函数实际上对图素执行了一次位操作,而且可以产生一些有趣的结果。
BitBlt函数从称为「来源」的设备内容中将一个矩形区的图素传输到称为「目的(destination)」的另一个设备内容中相同大小的矩形区。
来源和目的设备内容可以相同。
在BITBLT程序中,目的设备内容是窗口的显示区域,设备内容句柄从BeginPaint函数获得。来源设备内容是应用程序的整个窗口,此设备内容句柄从GetWindowDC获得的。很明显地,这两个设备内容指的是同一个实际设备(视讯显示器)。不过,这两个设备内容的坐标原点不同。
nXSrc和nYSrc参数指明了来源图像左上角的坐标位置。在BITBLT中,这两个参数设为0,表示图像从来源设备内容(也就是整个窗口)的左上角开始,nWidth和nHeight参数是图像的宽度和高度。BITBLT根据从GetSytemMetrics函数获得的信息来计算这些值。
nXDst和nYDst参数表示了复制图像位置左上角的坐标位置。在BITBLT中,这两个参数设定为不同的值以便多次复制图像。对于第一次BitBlt呼叫,这两个参数设制为0,将图像复制到显示区域的左上角位置。
BitBlt的最后一个参数是位映像操作型态。我将简短地讨论一下这个值。
请注意,BitBlt是从实际视讯显示内存传输图素,而不是从系统菜单图标的其它图像传输。如果您移动BITBLT窗口以使部分系统菜单图标移出屏幕,然后调整BITBLT窗口的尺寸使其重画,这时您将发现BITBLT显示区域中显示的是菜单图示的一部分。BitBlt函数不再存取整个图像。
hdcClient = BeginPaint (hwnd, &ps) ;
hdcWindow = GetWindowDC (hwnd) ;
for (y = 0 ; y < cyClient ; y += cySource)
for (x = 0 ; x < cxClient ; x += cxSource)
{
BitBlt (hdcClient, x, y, cxSource, cySource, hdcWindow, 0, 0, SRCCOPY) ;
}
ReleaseDC (hwnd, hdcWindow) ;
EndPaint (hwnd, &ps) ;
拉伸位图
在BitBlt函数中,目的图像与来源图像的尺寸是相同的,因为函数只有两个参数来说明宽度和高度。如果您想在复制时拉伸或者压缩图像尺寸,可以使用StretchBlt函数。StretchBlt函数的语法如下:
BOOL StretchBlt(
HDC hdcDest, // handle to destination device context
int nXOriginDest, // x-coordinate of upper-left corner of dest. rectangle
int nYOriginDest, // y-coordinate of upper-left corner of dest. rectangle
int nWidthDest, // width of destination rectangle
int nHeightDest, // height of destination rectangle
HDC hdcSrc, // handle to source device context
int nXOriginSrc, // x-coordinate of upper-left corner of source rectangle int nYOriginSrc, // y-coordinate of upper-left corner of source rectangle
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
DWORD dwRop // raster operation code
);
BitBlt和StretchBlt函数不是简单的位块传输。此函数实际在下面三种图像间执行位操作。
- Source 来源位图,拉伸或压缩(如果有必要)到目的矩形的尺寸。
- Destination 在BitBlt或StretchBlt呼叫之前的目的矩形。
- Pattern 在目的设备内容中选择的目前画刷,水平或垂直地复制到目的矩形范围内
结果是复制到了目的矩形中。
注:参考自<<windows程序设计>>
- Win32 库函数学习(一)
- C库函数学习(一) <string.h>
- win32多线程学习笔记(一)
- Win32汇编学习笔记(一)
- Win32汇编学习笔记(一)
- 学习 win32 sdk(一)
- win32编程学习(一)
- 机器学习实战(一)kNN调用scikit-learn库函数
- win32汇编基础学习一
- WIN32汇编学习笔记(一)
- C语言库函数(一)
- Oracle 库函数总结(一)
- Win32 API(一)
- Win32汇编学习笔记(罗云彬)(一)
- HTK学习笔记(一)在win32(win7)…
- WIN32汇编学习笔记(一) 汇编环境搭建
- Delphi Win32核心API参考学习记录(一)
- 《深入浅出MFC》学习笔记之Win32程序设计原理(一)
- 一个无聊男人的疯狂《数据结构与算法分析-C++描述》学习笔记 用C++/lua/python/bash的四重实现(2) IntCell类
- struts
- Linux下Poactor模式的高效实现
- i8一点通如何加载虚拟光驱玩游戏
- 关于WIndows 2008 HPC环境下的应用程序的开发
- Win32 库函数学习(一)
- 项目管理实践【三】每日构建【Daily Build Using CruiseControl.NET and MSBuild】
- c# Enum
- linux基本命令
- SOA服务的基本实现方法—使用HTTP协议传输XML请求(POX-over-HTTP)
- ant 安装使用
- vc ListCtrl查找某个字符所在的行数
- C# 操作文件夹及文件
- url-servlet