vb不能插入png图片_VB6.0载入PNG格式图片

展开全部

给你一个示例吧,显示PNG到e69da5e6ba903231313335323631343130323136353331333335313739FORM上,用GDI的:Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus

Private Declare Sub GdiplusShutdown Lib "gdiplus" (ByVal token As Long)

Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hwnd As Long, graphics As Long) As GpStatus

Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics 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 GdipLoadImageFromFile Lib "gdiplus" (ByVal filename As String, image As Long) As GpStatus

Private Declare Function GdipGetImageWidth Lib "gdiplus" (ByVal image As Long, Width As Long) As GpStatus

Private Declare Function GdipGetImageHeight Lib "gdiplus" (ByVal image As Long, Height As Long) As GpStatus

Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal image As Long) As GpStatus

Private Type GdiplusStartupInput

GdiplusVersion As Long

DebugEventCallback As Long

SuppressBackgroundThread As Long

SuppressExternalCodecs As Long

End Type

Private Enum GpStatus

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 Const c_pngPath As String = "C:\1.png"   '要显示的图片名称和路径。

Dim m_token As Long

Private Sub Form_paint() ‘Form上显示

Dim pImg As Long

Dim pGraphics As Long

Dim w As Long, h As Long

Call GdipCreateFromHDC(Me.hDC, pGraphics)

Call GdipLoadImageFromFile(StrConv(c_pngPath, vbUnicode), pImg)

Call GdipGetImageWidth(pImg, w)

Call GdipGetImageHeight(pImg, h)

Call GdipDrawImageRect(pGraphics, pImg, 0, 0, w, h)

Call GdipDisposeImage(pImg)

Call GdipDeleteGraphics(pGraphics)

End Sub

Private Sub Form_Load()

Dim StartupInput As GdiplusStartupInput

StartupInput.GdiplusVersion = 1

If GdiplusStartup(m_token, StartupInput, ByVal 0) Then

MsgBox "Error initializing GDI+"

Exit Sub

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

Call GdiplusShutdown(m_token)

End Sub

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值