|
本帖最后由 asd888 于 2015-11-13 10:16 编辑
源代码
Sub GdipLoadZoomImage(strFileName As String, PBox As PictureBox)
On Error Resume Next
Dim gdip_Token As Long
Dim gdip_Image As Long
Dim gdip_Graphics As Long
Dim lRet As Long
Dim iW As Long
Dim iH As Long
Dim pW As Single
Dim pH As Single
Dim GpInput As GdiplusStartupInput
GpInput.GdiplusVersion = 1
If GdiplusStartup(gdip_Token, GpInput) <> 0 Then Exit Sub
PBox.Cls
GdipLoadImageFromFile StrPtr(strFileName), gdip_Image
GdipGetImageWidth gdip_Image, iW
GdipGetImageHeight gdip_Image, iH
If gdip_Image Then GdipDisposeImage gdip_Image
If iW <> 0 And iH <> 0 Then
pW = PBox.ScaleWidth
pH = PBox.ScaleHeight
GetImageZoomSize iW, iH, pW, pH
PBox.Cls
If GdipCreateFromHDC(PBox.hDC, gdip_Graphics) = 0 Then
GdipLoadImageFromFile StrPtr(strFileName), gdip_Image
lRet = GdipDrawImageRect(gdip_Graphics, gdip_Image, _
(PBox.ScaleWidth - pW) \ 2, (PBox.ScaleHeight - pH) \ 2, pW, pH) '绘图
If gdip_Image Then GdipDisposeImage gdip_Image
GdipDeleteGraphics gdip_Graphics
End If
End If
GdiplusShutdown gdip_Token
End Sub
Function GetImageZoomSize(ByVal nSrcWidth As Integer, ByVal nSrcHeight As Integer, ByRef nDstWidth As Integer, ByRef nDstHeight As Integer)
If nSrcWidth / nSrcHeight < nDstWidth / nDstHeight Then
nDstWidth = nDstHeight * (nSrcWidth / nSrcHeight)
Else
nDstHeight = nDstWidth * (nSrcHeight / nSrcWidth)
End If
End Function
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|