| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1393 人关注过本帖
标题:为什么GDI+绘图失败????
只看楼主 加入收藏
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
结帖率:100%
收藏
 问题点数:0 回复次数:1 
为什么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


'--------------------------------------
'-- 使用者请保留作者版权
'--   作者:BEAR-BEN
'--   QQ:453628001
'--------------------------------------


'-------------缩略图函数-----------
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
ShowTNImg Picture1, "E:\A1100\已配主题\黄昏.jpg", Picture1.Width, Picture1.Height

图片路径正确,调用时候,老是提示 显示失败。
搜索更多相关主题的帖子: GDI 失败 绘图 
2010-03-25 20:30
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:0 
程序代码:
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 strptr(ImagePath), gdip_Image

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

     DisposeGDIP
End Sub
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal filename As any, Image As Long) As GpStatus
2010-06-12 00:21
快速回复:为什么GDI+绘图失败????
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046896 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved