Declare Function StretchBlt Lib "gdi32" Alias "StretchBlt" (ByVal hdc As Long,ByVal x As Long,ByVal y As Long,ByVal nWidth As Long,ByVal nHeight As Long,ByVal hSrcDC As Long,ByVal xSrc As Long,ByVal ySrc As Long,ByVal nSrcWidth As Long,ByVal nSrcHeight As Long,ByVal dwRop As Long) As Long |
可用GetDeviceCaps函数判断特定的设备场景是否支持此函数 不可选择对源位图进行剪切或旋转处理,源位图也不能是一个图元文件设备场景
StretchBlt是一个加强Bitblt功能的API函数,(Bitblt在VB本身的例程就有用于实现动画显示效果的例程),如果你比较这两个API函数的定义语句,会发现StretchBlt比Bitblt多出两个参数,即nSrcWidth和nSrcHeight(来源图象宽度和来源图像高度)。 例1:简单的显示一个图片 在BAS文件中定义 Option Explicit Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long,ByVal dwRop As Long) As Long Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long,ByVal dwRop As Long) As Long 在Form上放一个picture Box,并事先定义好一个图片,增加一个按钮 Option Explicit Private Sub Command1_Click() Dim w As Integer,h As Integer Me.ScaleMode = vbPixels w = Picture1.Width h = Picture1.Height StretchBlt Me.hdc,w,h,Picture1.hdc,vbSrcCopy End Sub 例2:放大或缩小图片 放大: Private Sub Command1_Click() Dim w As Integer,w * 2,h * 2,vbSrcCopy End Sub 缩小: Private Sub Command2_Click() Dim w As Integer,w / 2,h / 2,vbSrcCopy End Sub 例3:翻转图片左右翻转Private Sub Command1_Click() Dim w As Integer,h As Integer Me.ScaleMode = vbPixels w = Picture1.Width h = Picture1.Height StretchBlt Me.hdc,-w,vbSrcCopyEnd Sub上下翻转Private Sub Command2_Click() Dim w As Integer,vbSrcCopyEnd Sub左右并且上下翻转Private Sub Command3_Click() Dim w As Integer,-h,vbSrcCopyEnd Sub |