如何在VB中加载PNG格式的图片?
我要做一个VB程序,需要背景透明的图片,通过PS我可以搞定图片,但是GIF会失真,所以只能用PNG,但是VB中又不能直接加载PNG格式的,怎么办???请各位高手帮忙想想办...
我要做一个VB程序,需要背景透明的图片,通过PS我可以搞定图片,但是GIF会失真,所以只能用PNG,但是VB中又不能直接加载PNG格式的,怎么办???请各位高手帮忙想想办法!!!!!!
展开
7个回答
展开全部
用GDI函数,给你一个示例吧,显示PNG到FORM上,用GDI的:
'GDI+API函数
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
'先找指定控件ID,然后通过GDI将PNG内容画上...
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
运行结果:
本机XP+VB6测试通过!
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
展开全部
楼上那个装载PNG图片的代码太慢```
我觉得应该把PNG做进Flash里导出SWF,然后在VB里用Flash控件装载,再把Flash控件的WMode属性设置为Transparent,这样Flash控件的背景就透明了。
效果还是不错的。
我觉得应该把PNG做进Flash里导出SWF,然后在VB里用Flash控件装载,再把Flash控件的WMode属性设置为Transparent,这样Flash控件的背景就透明了。
效果还是不错的。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
假设你的图片的路径是c:\1.png
在form的load事件中写上
me.picture=loadpicture("c:\1.png")
就可以了,这是直接加载到窗体的,不需要picturebox控件。
在form的load事件中写上
me.picture=loadpicture("c:\1.png")
就可以了,这是直接加载到窗体的,不需要picturebox控件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
程序里面用透明图片肯定是考程序透空~直接用图片是最差的选择~
图片透空的方法 就是bltbit画出来~
图片透空的方法 就是bltbit画出来~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |