当前位置: 网学 > 编程文档 > VB > 正文

VB利用GDI+显示PNG图像

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式

vb使用PNG透明格式的图片其实是非常容易的,那就是使用XP以上操作系统中的GDI+库:

需要声明的GDI+的函数:
    Private Declare Function GdiplusStartup Lib "gdiplus.dll" ( _
    ByRef token As Long, _
    ByRef inputX As GdiplusStartupInput, _
    ByVal Output As Long _
    ) As Status
   
    Private Declare Sub GdiplusShutdown Lib "gdiplus.dll" (ByVal token As Long)


    Private Declare Function GdipCreateFromHDC Lib "gdiplus.dll" ( _
    ByVal hdc As Long, ByRef graphics As Long _
    ) As Status
   
   
    Private Declare Function GdipDrawImage Lib "gdiplus.dll" ( _
    ByVal graphics As Long, ByVal Image As Long, _
    ByVal X As Single, ByVal Y As Single _
    ) As Status
   


    Private Declare Function GdipLoadImageFromFile Lib "gdiplus.dll" ( _
    ByVal FileName As Long, ByRef Image As Long _
    ) As Status
   
Private Declare Function GdipDisposeImage Lib "gdiplus.dll" _
    (ByVal Image As Long) As Status

需要声明的结构:

    Private Type GdiplusStartupInput
    GdiplusVersion As Long
    DebugEventCallback As Long
    SuppressBackgroundThread As Long
    SuppressExternalCodecs As Long
    End Type

具体做法如下:

    Dim m_lngGraphics as long
    Dim m_lngInstance as long
    Dim m_lngPic as long

    Private Sub Form_Load() ''GDI+初始化
    Dim udtData As GdiplusStartupInput
   
    Randomize
   
    udtData.GdiplusVersion = 1

    If GdiplusStartup(app.hInstance, udtData, 0) Then
        MsgBox "GDI+ could not be initialized", vbCritical
        Exit Sub
    End If
   
    If GdipCreateFromHDC(Me.hdc, m_lngGraphics) Then
        MsgBox "Graphics object could not be created", vbCritical
        Exit Sub
    End If

    GdipLoadimagefromfile "c:\1.png" , m_lngPic
    GdipImageDraw m_lngGraphics,m_lngPic
End Sub

  • 上一篇资讯: vb中检测文件是否存在
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号