'============================================================== '试一试这个,看看是不是你想要的 '==============================================================Option ExplicitPrivate Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function SelectObject Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal hObject As Long) As LongPrivate Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Declare Function CreateCompatibleBitmap Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal nWidth As Long, _ ByVal nHeight As Long) As LongPrivate 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
Private Const SRCCOPY = &HCC0020Private Sub DrawBitmap(TheForm As Form, _ ByVal DstWidth As Long, ByVal DstHeight As Long, _ ByVal FileName As String) Dim SrcWidth As Long, SrcHeight As Long Dim Pic As New StdPicture Dim hBitmap As Long, hOldObject As Long Dim hMemDC As Long
Call SelectObject(hMemDC, hOldObject) Call DeleteObject(hBitmap) Call DeleteObject(hOldObject) Call DeleteDC(hMemDC) End Sub Private Sub Command1_Click() '在Form上画一个200*200相素的位图 DrawBitmap Me, 200, 200, "c:\test.bmp" End Sub
Me.PaintPicture Image1.Image,0,0,高,宽
用API应该不行吧?
笑话!
VB本身把Picture属性封装了
Picture属性与API的可能联系性趋向于0!
'试一试这个,看看是不是你想要的
'==============================================================Option ExplicitPrivate Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function SelectObject Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal hObject As Long) As LongPrivate Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Declare Function CreateCompatibleBitmap Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long) As LongPrivate 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
Private Const SRCCOPY = &HCC0020Private Sub DrawBitmap(TheForm As Form, _
ByVal DstWidth As Long, ByVal DstHeight As Long, _
ByVal FileName As String)
Dim SrcWidth As Long, SrcHeight As Long
Dim Pic As New StdPicture
Dim hBitmap As Long, hOldObject As Long
Dim hMemDC As Long
TheForm.AutoRedraw = True
Set Pic = LoadPicture(FileName)
hMemDC = CreateCompatibleDC(0)
hOldObject = SelectObject(hMemDC, Pic.Handle)
SrcHeight = TheForm.ScaleY(Pic.Height, vbHimetric, vbPixels)
SrcWidth = TheForm.ScaleX(Pic.Width, vbHimetric, vbPixels)
Call StretchBlt(TheForm.hdc, 0, 0, DstWidth, DstHeight, _
hMemDC, 0, 0, SrcWidth, SrcHeight, SRCCOPY)
TheForm.Refresh
Call SelectObject(hMemDC, hOldObject)
Call DeleteObject(hBitmap)
Call DeleteObject(hOldObject)
Call DeleteDC(hMemDC)
End Sub
Private Sub Command1_Click()
'在Form上画一个200*200相素的位图
DrawBitmap Me, 200, 200, "c:\test.bmp"
End Sub