首页 >> 读书频道 >> 电脑 >> 放大缩小翻转 BitMap图
 
· 网络数据库教程十
· 同步问题 Semapho
· 同步问题 Mutex的使
· 同步问题 Event的使
· 制造出透明的Form
· 窗体缩小到右下角
· 网络数据库教程八
· 如何直接开启一个文件
· 如何让Window不接受
· 网络数据库教程七
· KeyBoard Key
· 更动MsgBox But
 
· 电视剧《刁蛮公主》下载和
· 美容养颜手册
· 加油金顺剧情分集介绍完整
· 红楼梦:120回全本[清
· 素质教育在美国
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 武林寓言故事
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

放大缩小翻转 BitMap图


查看有无更新版本

关键字:VB 2006-9-18

 

一般来说我们会使用PaintPicture来完成,而这个方法和StretchBlt的使用很类似,在
此提出两种不同的方式来达放大缩小翻转图形,使用API的DrawBitMap只能使用BitMap图
,而没有API的PaintPicture则无此限制,但DrawBitMap在处理大的图形时,可能较快
些吧。

StretchBlt 其定义如下:
Declare Function StretchBlt Lib "gdi32" (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

hdc 待绘图的hDc
x, y 待绘图目标的起点座标
nWidth, nHeight  绘图的长宽(by Pixels)
hSrcDc 来源Dc
xSrc, ySrc 来源图的起点座标
nSrcWidth, nSrcHeight 来源图的长宽
dwRop 绘图的方式

由以上的叁数,我们知道事实上可以取来源图的一部份(方形区域)来缩放,而目的绘图
区呢,它可以指定从某个起始座标开始画(不一定 (0,0) ),而nWidth与nHeight控制图
的缩放,例如说nWidth = CLng(1.5 * nSrcWidth), nHeight = CLng(nSrcHeight * 1.5)
那代表比原图放大1.5倍,如果nWidth = -1 * nSrcWidth 表该图会左右相反,而
nHeight = -1 * nSrcHeight 时则会有上正颠倒的图出现。以下提供一个副程式,该副
程式简化了StretchBlt,允许我们画一个图於Form/PictureBox的左上角,并可以放大
缩小或翻转。

DrawBitMap(Dst As Object, ByVal xRate As Double, _
       ByVal yRate As Double, ByVal FileName As String)

该副程式中
hDst    是待绘图的物件(可以为Form或PictureBox)
xRate    宽度缩放比例
rRate    长度缩放比例
FileName   图形档名


'以下在.BasOption ExplicitDeclare Function StretchBlt Lib "gdi32" (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 LongDeclare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongDeclare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongDeclare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongConst SRCCOPY = &HCC0020Public Sub DrawBitMap(Dst As Object, ByVal xRate As Double, _ ByVal yRate As Double, ByVal FileName As String)Dim dstWidth As Long, dstHeight As LongDim srcWidth As Long, srcHeight As LongDim x As Long, y As LongDim pic As StdPictureDim hDc5 As Long, i As LongSet pic = LoadPicture(FileName) '读取图形档hDc5 = CreateCompatibleDC(0) '建立Memory DCi = SelectObject(hDc5, pic.Handle) '在该memoryDC上放上bitmap图srcHeight = Dst.ScaleY(pic.Height, vbHimetric, vbPixels)srcWidth = Dst.ScaleX(pic.Width, vbHimetric, vbPixels)dstHeight = CLng(srcHeight * yRate)If dstHeight < 0 Then y = -1 * dstHeightElse y = 0End IfdstWidth = CLng(srcWidth * xRate)If dstWidth < 0 Then x = -1 * dstWidthElse x = 0End IfCall StretchBlt(Dst.hdc, x, y, dstWidth, dstHeight, hDc5, 0, 0, srcWidth, srcHeight, SRCCOPY)Call DeleteDC(hDc5)End SubPublic Sub DrawPicture(Dst As Object, ByVal xRate As Double, _ ByVal yRate As Double, ByVal FileName As String)Dim dstWidth As Long, dstHeight As LongDim srcWidth As Long, srcHeight As LongDim x As Long, y As LongDim pic As StdPictureDim i As LongSet pic = LoadPicture(FileName) '读取图形档srcHeight = Dst.ScaleY(pic.Height, vbHimetric, vbPixels)srcWidth = Dst.ScaleX(pic.Width, vbHimetric, vbPixels)dstHeight = CLng(srcHeight * yRate)If dstHeight < 0 Then y = -1 * dstHeightElse y = 0End IfdstWidth = CLng(srcWidth * xRate)If dstWidth < 0 Then x = -1 * dstWidthElse x = 0End IfDst.ScaleMode = 3Dst.PaintPicture pic, x, y, dstWidth, dstHeight, 0, 0, srcWidth, srcHeightEnd Sub'以下在Form需两个command button一个PictureBoxPrivate Sub Command1_Click()Call DrawBitMap(Me, 1.5, -1.5, "c:\windows\circles.bmp") '放大1.5倍并上下翻转End SubPrivate Sub Command2_Click()Call DrawBitMap(Picture1, 1.5, -1.5, "c:\windows\client.ico") '放大1.5倍并上下翻转End Sub

放大缩小翻转 BitMap图

[ 1 ]
放大缩小翻转 BitMap图 num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑