VB利用GDI+显示PNG图像

在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

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值