• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

雨滴式的显示图片

发布: 2007-7-14 20:28 | 作者: 佚名    | 来源: 网络转载     | 查看: 13次 | 进入软件测试论坛讨论

领测软件测试网   本范例是以一个stdPicture物件来存图形,之後於PictureBox中以特殊效果来显示。 因为我们想显示的只有一个图,所以不想多用另一个PictureBox来存原始图,而后再画到另一个PictureBox上,那只有用StdPicture 物件来取代PictureBox(存来源图),但是BitBlt这个绘图函式需来源与目的的hDc,而StdPicture物件没有hDc,它只有一个Handle值,以本例来说,这Handle值便是图形的hBitmap值。所以我们只好使用 MemoryDC的方式来做,产生一个MemoryDc後将BitMap图放於其上,之後便可以使用BitBlt来绘图了。'需求一个PictureBox( Named picture2),一个Command按键)

Option Explicit

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long

Private Declare Function CreateCompatibleDC Lib "gdi32" _

(ByVal hdc As Long) As Long

Private Declare Function SelectObject Lib "gdi32" _

(ByVal hdc As Long, ByVal hObject As Long) As Long

Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

Const SRCCOPY = HCC0020

Private Picture1 As New StdPicture


Private Sub Command1_Click()

Dim i As Long

Dim j As Long

Dim height5 As Long, width5 As Long

Dim hMemDc As Long


'stdPicture物件的度量单位是Himetric所以要转换成Pixel

height5 = ScaleY(Picture1.Height, vbHimetric, vbPixels)

If height5 > Picture2.ScaleHeight Then

height5 = Picture2.ScaleHeight

End If

width5 = ScaleX(Picture1.Width, vbHimetric, vbPixels)

If width5 > Picture2.ScaleWidth Then

width5 = Picture2.ScaleWidth

End If

'Create Memory DC

hMemDc = CreateCompatibleDC(Picture2.hdc)

|'将Picture1的BitMap图指定给hMemDc

Call SelectObject(hMemDc, Picture1.Handle)

For i = height5 To 1 Step -1

Call BitBlt(Picture2.hdc, 0, i, width5, 1, _

hMemDc, 0, i, SRCCOPY)

For j = i - 1 To 1 Step -1

Call BitBlt(Picture2.hdc, 0, j, width5, 1, _

hMemDc, 0, i, SRCCOPY)

Next j

Next

Call DeleteDC(hMemDc)

End Sub


Private Sub Form_Load()

Dim i As Long

Picture2.ScaleMode = 3 '设定成Pixel的度量单位

'设定待Display的图

Set Picture1 = LoadPicture("c:\windows\aaa.bmp")

' ^^^^^^^^^^^^^^^^^^^^^^

' Load the picture we want to show

End Sub

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网