'***************************************************
' 将图片在PictureBox控件中按比例缩放后,居中显示
'***************************************************
Public Sub PictureToCenter(tPic As Picture, PicBox As PictureBox)
Dim PicH As Long, PicW As Long
Dim PicBoxW As Long, PicBoxH As Long
Dim PicRate As Single, PicBoxRate As Single
Dim NewH As Long, NewW As Long
Private 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 Sub Command1_Click()
'利用picture2作为缓冲
Picture2.Picture = LoadPicture("F:\pictures\sniper\awp_a.jpg")
StretchBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, vbSrcCopy
Picture1.Refresh
End Sub
Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture2.AutoSize = True
Picture2.Visible = False
End Sub