vb中
Public Sub showPicInGDIPlus(Path As String, picCtrl As PictureBox)
Dim Status As Long
Dim token As Long
Dim typGPInput As GdiplusStartupInput
Dim wkPic As PictureBox
Dim Rtn As Long
Dim ImageMode
Rtn = 0
ImageMode = 1
Set wkPic = picCtrl
wkPic.AutoRedraw = True
wkPic.ScaleMode = vbPixels
'GDI+初期化
typGPInput.GdiplusVersion = 1
Status = GdiplusStartup(token, typGPInput)
If Status <> 0 Then
Exit Sub
End If
Dim img As Long
Status = GdipLoadImageFromFile(StrPtr(Path), img)
If Status = 0 Then
wkPic.Cls
Dim G As Long
Status = GdipCreateFromHDC(wkPic.hdc, G)
If Status = 0 Then
Dim mode As InterpolationMode
mode = ImageMode
Status = GdipSetInterpolationMode(G, mode)
If Status <> 0 Then
'Graphics解放
Call GdipDeleteGraphics(G)
'描画
Call GdipDisposeImage(img)
'GDI+後始末処理実施
Call GdiplusShutdown(token)
Exit Sub
End If
'描画
Status = GdipDrawImageRectI(G, img, 0, 0, wkPic.ScaleWidth, wkPic.ScaleHeight)
If Status <> 0 Then
'描画用Graphics解放
Call GdipDeleteGraphics(G)
'描画
Call GdipDisposeImage(img)
'GDI+後始末処理実施
Call GdiplusShutdown(token)
Exit Sub
End If
'描画用Graphics解放
Call GdipDeleteGraphics(G)
End If
wkPic.Refresh
'描画
Call GdipDisposeImage(img)
End If
'GDI+後始末処理実施
Call GdiplusShutdown(token)
On Error GoTo 0
Exit Sub
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------
以上为vb版本,显示图片没有问题
以下为升级后的vb.net版本(简约版本)
-------------------------------------------------------------------------------------------------------------------------------------------------