VB简单看图程序: Option Explicit 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 LongConst Srccopy = &HCC0020 Private Sub Command1_Click() CommonDialog1.ShowOpen bakPic.Picture = LoadPicture(CommonDialog1.FileName)
Dim wScale As Double Dim hScale As Double Dim newWidth As Double Dim newHeight As Double
Dim newLeft As Double Dim newTop As Double wScale = Picture1.Width / bakPic.Width hScale = Picture1.Height / bakPic.Height If wScale > hScale Then newWidth = bakPic.Width * hScale newHeight = bakPic.Height * hScale Else newWidth = bakPic.Width * wScale newHeight = bakPic.Height * wScale End If newLeft = (Picture1.Width - newWidth) / 2 newTop = (Picture1.Height - newHeight) / 2 Picture1.Cls
StretchBlt Picture1.hdc, newLeft, newTop, newWidth, newHeight, bakPic.hdc, 0, 0, bakPic.ScaleWidth, bakPic.ScaleHeight, Srccopy Picture1.Refresh End SubPrivate Sub Form_Load() bakPic.AutoRedraw = True bakPic.Visible = False Me.ScaleMode = 3 Picture1.ScaleMode = 3 bakPic.ScaleMode = 3 End Sub
Option Explicit
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 LongConst Srccopy = &HCC0020
Private Sub Command1_Click()
CommonDialog1.ShowOpen
bakPic.Picture = LoadPicture(CommonDialog1.FileName)
Dim wScale As Double Dim hScale As Double
Dim newWidth As Double
Dim newHeight As Double
Dim newLeft As Double
Dim newTop As Double
wScale = Picture1.Width / bakPic.Width hScale = Picture1.Height / bakPic.Height If wScale > hScale Then newWidth = bakPic.Width * hScale newHeight = bakPic.Height * hScale Else newWidth = bakPic.Width * wScale newHeight = bakPic.Height * wScale End If
newLeft = (Picture1.Width - newWidth) / 2 newTop = (Picture1.Height - newHeight) / 2 Picture1.Cls
StretchBlt Picture1.hdc, newLeft, newTop, newWidth, newHeight, bakPic.hdc, 0, 0, bakPic.ScaleWidth, bakPic.ScaleHeight, Srccopy Picture1.Refresh
End SubPrivate Sub Form_Load()
bakPic.AutoRedraw = True
bakPic.Visible = False
Me.ScaleMode = 3
Picture1.ScaleMode = 3
bakPic.ScaleMode = 3
End Sub