VB GDI+的问题

对GDI+不是很了解,下面这代码,按钮多按几次,图片就显示不出来了,谁能改改?PrivateTypeGdiplusStartupInputGdiplusVersionAs... 对GDI+不是很了解,下面这代码,按钮多按几次,图片就显示不出来了,谁能改改?
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type

Private Enum GpStatus 'Status
Ok = 0
GenericError = 1
InvalidParameter = 2
OutOfMemory = 3
ObjectBusy = 4
InsufficientBuffer = 5
NotImplemented = 6
Win32Error = 7
WrongState = 8
Aborted = 9
FileNotFound = 10
ValueOverflow = 11
AccessDenied = 12
UnknownImageFormat = 13
FontFamilyNotFound = 14
FontStyleNotFound = 15
NotTrueTypeFont = 16
UnsupportedGdiplusVersion = 17
GdiplusNotInitialized = 18
PropertyNotFound = 19
PropertyNotSupported = 20
End Enum

Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus
Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As GpStatus
Private Declare Function GdipDrawImageRect Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As GpStatus
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, graphics As Long) As GpStatus
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatus
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal filename As String, Image As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As GpStatus

Dim gdip_Token As Long
Dim gdip_Image As Long
Dim gdip_Graphics As Long
Dim i As Integer

'-------------缩略图函数-----------
Public Sub ShowTNImg(PBox As Object, ImagePath As String, WidthMax As Long, HeightMax As Long)
LoadGDIP
If GdipCreateFromHDC(PBox.hDC, gdip_Graphics) <> 0 Then
MsgBox "出现错误!", vbCritical, "错误"
GdiplusShutdown gdip_Token
End
End If

'载入图片到内存中
GdipLoadImageFromFile StrConv(ImagePath, vbUnicode), gdip_Image

'使用GDI+直接从内存中缩略并绘图,GDI+有很好的反锯齿能力
If GdipDrawImageRect(gdip_Graphics, gdip_Image, 0, 0, WidthMax, HeightMax) <> Ok Then Debug.Print "显示失败"

DisposeGDIP
End Sub

Public Sub LoadGDIP()
Dim GpInput As GdiplusStartupInput
GpInput.GdiplusVersion = 1
If GdiplusStartup(gdip_Token, GpInput) <> 0 Then
MsgBox "加载GDI+失败!", vbCritical, "加载错误"
End
End If
End Sub

Public Sub DisposeGDIP()
GdipDisposeImage gdip_Image
GdipDeleteGraphics gdip_Graphics
GdiplusShutdown gdip_Token
End Sub
太长了,还有:

Private Sub Command1_Click()
i = i + 1
Picture1.Picture = LoadPicture("")
Call ShowTNImg(Picture1, "F:\1\" & i & ".jpg", Picture1.Width / 15, Picture1.Height / 15)
'Label1.Caption = i
End Sub

Private Sub Form_Load()
i = 0
End Sub

用别的电脑试了下,还真是....
我再找别人试下= =
破电脑,问题真多
展开
 我来答
ljl88900
2010-05-05 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2629万
展开全部
没问题呀,我一口气按了50次都正常显示。
启帆信息
2024-11-22 广告
作为启帆信息科技股份有限公司的工作人员,对于Omniverse View有一定了解。Omniverse View是NVIDIA Omniverse平台中的一个强大工具,它易于导航且功能丰富,可以支持任何技能水平的专业人员展示和审查3D设计项... 点击进入详情页
本回答由启帆信息提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式