vb不能插入png图片_VB读取PNG格式图片解决办法

这段VB.NET代码展示了如何初始化GDI+,加载图像文件,创建图形上下文,并进行绘制。在`Command1_Click`事件中,它尝试从指定路径加载PNG图像。而在`Form_Load`事件中,初始化GDI+的过程会显示成功或失败的消息。这些函数包括GDI+的启动、关闭、创建图形上下文、删除图形上下文、加载图像和释放图像资源等核心操作。
摘要由CSDN通过智能技术生成

VB.NET codeOption 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, outputbuf As Long) As Long

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 Command1_Click()

Dim a As GpStatus

a = GdipLoadImageFromFile("F:\1.png", vbUnicode)

End Sub

Private Sub Form_Load()

Dim GpInput As GdiplusStartupInput

GpInput.GdiplusVersion = 1

If GdiplusStartup(gdip_Token, GpInput, 0) <> 0 Then

MsgBox "加载GDI+失败!", vbCritical, "加载错误"

End

Else

MsgBox "加载GDI+成功!", vbCritical, "加载成功"

End If

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值