雨滴式的显示图片
2006-02-27 11:56:12 来源:WEB开发网核心提示:本范例是以一个stdPicture物件来存图形,之後於PictureBox中以特殊效果来显示,雨滴式的显示图片,因为我们想显示的只有一个图,所以不想多用另一个PictureBox来存原始图,产生一个MemoryDc後将BitMap图放於其上,之後便可以使用BitBlt来绘图了,而後再画到另一个PictureBox上,那
本范例是以一个stdPicture物件来存图形,之後於PictureBox中以特殊效果来显示。因为我们想显示的只有一个图,所以不想多用另一个PictureBox来存原始图,而後再画到另一个PictureBox上,那只有用StdPicture物件来取代PictureBox(存来源图),但是BitBlt这个绘图函式需来源与目的的hDc,而StdPicture物件没有hDc,它只有一个Handle值,以本例来说,这Handle值便是图形的hBitmap值。所以我们只好使用MemoryDC的方式来做,产生一个MemoryDc後将BitMap图放於其上,之後便可以使用BitBlt来绘图了。'需求一个PictureBox(Namedpicture2),一个Command按键)
OptionExplicit
PRivateDeclareFunctionBitBltLib"gdi32"(ByValhDestDCAsLong,ByValxAsLong,ByValyAsLong,ByValnWidthAsLong,ByValnHeightAsLong,ByValhSrcDCAsLong,ByValxSrcAsLong,ByValySrcAsLong,ByValdwRopAsLong)AsLong
PrivateDeclareFunctionCreateCompatibleDCLib"gdi32"(ByValhdcAsLong)AsLong
PrivateDeclareFunctionSelectObjectLib"gdi32"(ByValhdcAsLong,ByValhObjectAsLong)AsLong
PrivateDeclareFunctionDeleteDCLib"gdi32"(ByValhdcAsLong)AsLong
ConstSRCCOPY=&HCC0020
PrivatePicture1AsNewStdPicture
PrivateSubCommand1_Click()
DimiAsLong
DimjAsLong
Dimheight5AsLong,width5AsLong
DimhMemDcAsLong
'stdPicture物件的度量单位是Himetric所以要转换成Pixel
height5=ScaleY(Picture1.Height,vbHimetric,vbPixels)
Ifheight5>Picture2.ScaleHeightThen
height5=Picture2.ScaleHeight
EndIf
width5=ScaleX(Picture1.Width,vbHimetric,vbPixels)
Ifwidth5>Picture2.ScaleWidthThen
width5=Picture2.ScaleWidth
EndIf
'CreateMemoryDC
hMemDc=CreateCompatibleDC(Picture2.hdc)
'将Picture1的BitMap图指定给hMemDc
CallSelectObject(hMemDc,Picture1.Handle)
Fori=height5To1Step-1
CallBitBlt(Picture2.hdc,0,i,width5,1,hMemDc,0,i,SRCCOPY)
Forj=i-1To1Step-1
CallBitBlt(Picture2.hdc,0,j,width5,1,hMemDc,0,i,SRCCOPY)
Nextj
Next
CallDeleteDC(hMemDc)
EndSub
PrivateSubForm_Load()
DimiAsLong
Picture2.ScaleMode=3'设定成Pixel的度量单位
'设定待Display的图
SetPicture1=LoadPicture("c:\windows\素还真.bmp")
'^^^^^^^^^^^^^^^^^^^^^^
'Loadthepicturewewanttoshow
EndSub->
OptionExplicit
PRivateDeclareFunctionBitBltLib"gdi32"(ByValhDestDCAsLong,ByValxAsLong,ByValyAsLong,ByValnWidthAsLong,ByValnHeightAsLong,ByValhSrcDCAsLong,ByValxSrcAsLong,ByValySrcAsLong,ByValdwRopAsLong)AsLong
PrivateDeclareFunctionCreateCompatibleDCLib"gdi32"(ByValhdcAsLong)AsLong
PrivateDeclareFunctionSelectObjectLib"gdi32"(ByValhdcAsLong,ByValhObjectAsLong)AsLong
PrivateDeclareFunctionDeleteDCLib"gdi32"(ByValhdcAsLong)AsLong
ConstSRCCOPY=&HCC0020
PrivatePicture1AsNewStdPicture
PrivateSubCommand1_Click()
DimiAsLong
DimjAsLong
Dimheight5AsLong,width5AsLong
DimhMemDcAsLong
'stdPicture物件的度量单位是Himetric所以要转换成Pixel
height5=ScaleY(Picture1.Height,vbHimetric,vbPixels)
Ifheight5>Picture2.ScaleHeightThen
height5=Picture2.ScaleHeight
EndIf
width5=ScaleX(Picture1.Width,vbHimetric,vbPixels)
Ifwidth5>Picture2.ScaleWidthThen
width5=Picture2.ScaleWidth
EndIf
'CreateMemoryDC
hMemDc=CreateCompatibleDC(Picture2.hdc)
'将Picture1的BitMap图指定给hMemDc
CallSelectObject(hMemDc,Picture1.Handle)
Fori=height5To1Step-1
CallBitBlt(Picture2.hdc,0,i,width5,1,hMemDc,0,i,SRCCOPY)
Forj=i-1To1Step-1
CallBitBlt(Picture2.hdc,0,j,width5,1,hMemDc,0,i,SRCCOPY)
Nextj
Next
CallDeleteDC(hMemDc)
EndSub
PrivateSubForm_Load()
DimiAsLong
Picture2.ScaleMode=3'设定成Pixel的度量单位
'设定待Display的图
SetPicture1=LoadPicture("c:\windows\素还真.bmp")
'^^^^^^^^^^^^^^^^^^^^^^
'Loadthepicturewewanttoshow
EndSub->
赞助商链接