| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2220 人关注过本帖
标题:为什么GDI+绘图失败啊
只看楼主 加入收藏
ylof1986
Rank: 2
等 级:论坛游民
帖 子:241
专家分:61
注 册:2008-1-6
结帖率:93.94%
收藏
已结贴  问题点数:20 回复次数:4 
为什么GDI+绘图失败啊
在窗口中就正常,如果将源码转到用户控件中想在用户控件中绘图就会失败啊
Option Explicit
Private Type GdiplusStartupInput
    GdiplusVersion As Long ' Must be 1 for GDI+ v1.0, the current version as of this writing.
    DebugEventCallback As Long ' Ignored on free builds
    SuppressBackgroundThread As Long ' FALSE unless you're prepared to call
    ' the hook/unhook functions properly
    SuppressExternalCodecs As Long ' FALSE unless you want GDI+ only to use
    ' its internal image codecs.
End Type
Private Enum GpStatus ' aka 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 GdipDrawImage Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal x As Single, ByVal y 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_pngImage As Long
Dim gdip_Graphics As Long

Private Sub UserControl_Initialize()
Dim GpInput As GdiplusStartupInput
GpInput.GdiplusVersion = 1
If GdiplusStartup(gdip_Token, GpInput) <> Ok Then
    MsgBox "加载GDI+失败!", vbCritical, "加载错误"
    End
End If
If GdipCreateFromHDC(UserControl.hDC, gdip_Graphics) <> Ok Then
    MsgBox "出现错误!", vbCritical, "错误"
    GdiplusShutdown gdip_Token
    End
Else
Debug.Print UserControl.hDC
End If
GdipLoadImageFromFile StrConv(App.Path & "\Show.png", vbUnicode), gdip_pngImage '加载文件
End Sub

Private Sub UserControl_Paint()
If GdipDrawImage(gdip_Graphics, gdip_pngImage, 0, 0) <> Ok Then Debug.Print "显示失败。。。"  '就是这步会失败
End Sub

Private Sub UserControl_Terminate()
GdipDisposeImage gdip_pngImage
GdipDeleteGraphics gdip_Graphics
GdiplusShutdown gdip_Token
End Sub


======================================
我知道那里错误了,是StrConv(App.Path & "\Show.png", vbUnicode)这里错误了,app.path中含有透明两个字,结果如果换了其他字就好了,但是也不知道还有没有其他中文不行,这是怎么搞的啊

[ 本帖最后由 ylof1986 于 2010-3-24 10:51 编辑 ]
搜索更多相关主题的帖子: 失败 绘图 GDI 
2010-03-24 10:07
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:5 
   Dim gs As GpStatus
  
   gs = GdipLoadImageFromFile( StrConv(App.Path & "\Show.png", vbUnicode), gdip_pngImage) '加载文件
   Debug.print gs = GpStatus.Ok,gs
2010-03-24 11:44
ylof1986
Rank: 2
等 级:论坛游民
帖 子:241
专家分:61
注 册:2008-1-6
收藏
得分:0 
以下是引用bczgvip在2010-3-24 11:44:59的发言:

   Dim gs As GpStatus
   
   gs = GdipLoadImageFromFile( StrConv(App.Path & "\Show.png", vbUnicode), gdip_pngImage) '加载文件
   Debug.print gs = GpStatus.Ok,gs
deBug如下
False 3

然后3是OutOfMemory

图片是一个24.4KB的PNG图像,我内存2G

[ 本帖最后由 ylof1986 于 2010-3-24 14:42 编辑 ]
2010-03-24 14:39
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:15 
程序代码:
Option Explicit
Private Type GdiplusStartupInput
    GdiplusVersion As Long ' Must be 1 for GDI+ v1.0, the current version as of this writing.
    DebugEventCallback As Long ' Ignored on free builds
    SuppressBackgroundThread As Long ' FALSE unless you're prepared to call
    ' the hook/unhook functions properly
    SuppressExternalCodecs As Long ' FALSE unless you want GDI+ only to use
    ' its internal image codecs.
End Type
Private Enum GpStatus ' aka 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 GdipDrawImage Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal x As Single, ByVal y 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 Any, Image As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As GpStatus
Dim gdip_Token As Long
Dim gdip_pngImage As Long
Dim gdip_Graphics As Long

Private Sub UserControl_Initialize()
Dim GpInput As GdiplusStartupInput
GpInput.GdiplusVersion = 1
If GdiplusStartup(gdip_Token, GpInput) <> Ok Then
    MsgBox "加载GDI+失败!", vbCritical, "加载错误"
    End
End If
If GdipCreateFromHDC(UserControl.hDC, gdip_Graphics) <> Ok Then
    MsgBox "出现错误!", vbCritical, "错误"
    GdiplusShutdown gdip_Token
    End
Else
Debug.Print UserControl.hDC
End If
Dim gs As GpStatus, sTmp$
sTmp$ = App.Path & "\Show.png"
gs = GdipLoadImageFromFile(StrPtr(sTmp$), gdip_pngImage)   '加载文件
Debug.Print gs = GpStatus.Ok, gs
End Sub

Private Sub UserControl_Paint()
If GdipDrawImage(gdip_Graphics, gdip_pngImage, 0, 0) <> Ok Then Debug.Print "显示失败。。。"  '就是这步会失败
End Sub

Private Sub UserControl_Terminate()
GdipDisposeImage gdip_pngImage
GdipDeleteGraphics gdip_Graphics
GdiplusShutdown gdip_Token
End Sub


2010-03-24 15:02
ylof1986
Rank: 2
等 级:论坛游民
帖 子:241
专家分:61
注 册:2008-1-6
收藏
得分:0 
老大,Any和StrPtr为啥在对象浏览器中找不到啊

还有怎样查找某个API的声明啊

[ 本帖最后由 ylof1986 于 2010-3-25 13:43 编辑 ]
2010-03-25 13:29
快速回复:为什么GDI+绘图失败啊
数据加载中...
 
   



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

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