原生的VB6不支持PNG个图片,因为刚有VB的时候还没有PNG的概念呢。不过,利用GDI+加载解析个PNG简直是砍瓜切菜般简单。

GDI+的模块是我在网上下载的,地址应该是:http://vistaswx.com/blog/article/gdip-tutorial-6-image

上代码:

 'code by lichmama from cnblogs.com
'@vb6.0 gdi+ png
Private Sub DrawPng(ByVal pngfile As String, _
Optional Left As Long = &, _
Optional Top As Long = &, _
Optional zoom As Single = #) Dim Graphic As Long
Dim Image As Long
Dim imgWidth As Long
Dim imgHeight As Long Call GdipCreateFromHDC(Me.hDC, Graphic)
Call GdipSetSmoothingMode(Graphic, SmoothingModeAntiAlias)
Call GdipLoadImageFromFile(StrPtr(pngfile), Image)
Call GdipGetImageWidth(Image, imgWidth)
Call GdipGetImageHeight(Image, imgHeight)
Call GdipDrawImageRect(Graphic, Image, & + Left, & + Top, imgWidth * zoom, imgHeight * zoom) Call GdipDisposeImage(Image)
Call GdipDeleteGraphics(Graphic)
End Sub Private Sub Command1_Click()
Call DrawPng("D:\迅雷下载\rio-2-icons\rio-2-tulio-icon-2.png", -&, -&)
Call DrawPng("D:\迅雷下载\rio-2-icons\rio-2-linda-icon-2.png", &)
Call DrawPng("D:\迅雷下载\rio-2-icons\rio-2-logo.png", , &, 0.5)
Call DrawPng("D:\迅雷下载\rio-2-icons\rio-2-kids-icon.png", &, &, 0.25)
Call DrawPng("D:\迅雷下载\rio-2-icons\rio-2-nico-&-pedro-icon.png", &, &, 0.25)
Call DrawPng("D:\迅雷下载\rio-2-icons\rio-2-luiz-icon.png", &, &, 0.25)
End Sub Private Sub Form_Load()
Call InitGDIPlus
End Sub Private Sub Form_Unload(Cancel As Integer)
Call TerminateGDIPlus
End Sub

贴张图:

从资源文件加载PNG:

Private Function GdipCreateImageFromStream(ByVal resid As Integer, _
ByVal restype As String) As Long Dim Image As Long
Dim ResData() As Byte
Dim IStream As Object
Dim hGlobal As Long
Dim pMem As Long ResData = LoadResData(resid, restype)
hGlobal = GlobalAlloc(GMEM_MOVEABLE, UBound(ResData) + )
pMem = GlobalLock(hGlobal)
If pMem = Then
Debug.Print "Global Alloc Failed."
Erase ResData
Exit Function
End If
Call RtlMoveMemory(ByVal pMem, ResData(), UBound(ResData) + )
Call GlobalUnlock(hGlobal)
Call CreateStreamOnHGlobal(hGlobal, False, IStream)
Call GdipLoadImageFromStream(IStream, Image) Set IStream = Nothing
Call GlobalFree(hGlobal)
GdipCreateImageFromStream = Image
End Function
Private Sub Command1_Click()
Dim Graphics As Long
Dim Image As Long Call GdipCreateFromHDC(Me.hDC, Graphics)
Call GdipSetSmoothingMode(Graphics, SmoothingModeAntiAlias)
'调用方式如下
Image = GdipCreateImageFromStream(, "PNG")
Call GdipDrawImage(Graphics, Image, &, &) Call GdipDisposeImage(Image)
Call GdipDeleteGraphics(Graphics)
End Sub

贴张图:

VB6之GDI+加载PNG图片的更多相关文章

  1. win32用GDI+加载png图片作为背景图

    #include <windows.h> #include <gdiplus.h> /* GDI+ startup token */ ULONG_PTR gdiplusStar ...

  2. GDI+ 加载PNG图片

    #include <GdiPlus.h>#pragma comment(lib, "GdiPlus.lib")using namespace Gdiplus; clas ...

  3. VC中使用GDI+实现为按钮加载Png图片

    http://blog.csdn.net/flyfish1986/article/details/5381605 VC中使用GDI+实现为按钮加载Png图片 http://www.codeprojec ...

  4. WebView加载HTML图片大小自适应与文章自动换行

    http://www.brighttj.com/ios/ios-webview-load-html-image-adaptive.html 在很多App中都会使用到webview,尤其是在加载新闻内容 ...

  5. Android ListView 图片异步加载和图片内存缓存

    开发Android应用经常需要处理图片的加载问题.因为图片一般都是存放在服务器端,需要联网去加载,而这又是一个比较耗时的过程,所以Android中都是通过开启一个异步线程去加载.为了增加用户体验,给用 ...

  6. WPF中加载高分辨率图片性能优化

    在最近的项目中,遇到一个关于WPF中同时加载多张图片时,内存占用非常高的问题. 问题背景: 在一个ListView中同时加载多张图片,注意:我们需要加载的图片分辨率非常高. 代码: XAML: < ...

  7. Fresco 使用笔记(一):加载gif图片并播放

    项目总结 --------------------------------------------------------------------- 前言: 项目中图文混合使用的太多太多了,但是绝大部 ...

  8. 图片_ _Android有效解决加载大图片时内存溢出的问题 2

    Android有效解决加载大图片时内存溢出的问题 博客分类: Android Android游戏虚拟机算法JNI 尽量不要使用setImageBitmap或 setImageResource或 Bit ...

  9. Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子

    Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子 procedure TForm1.Button1Click(Sender: TObject); ...

随机推荐

  1. Lists, Maps and Sets in Java

    ArrayList vs LinkedList vs Vector From the hierarchy diagram, they all implement List interface. The ...

  2. 2.solr学习速成之安装

    1.下载解压solr-5.3.1.tgz [root@205 opt]# tar -zxf solr-5.3.1.tgz -C /opt/module/ 2.将solr-5.3.1/server/so ...

  3. 4.docker学习之镜像

    镜像 我们知道,我们想在Windows操作系统上跑Linux,需要安装一个虚拟机程序,然后下载一个Linux镜像,在该虚拟机程序中创建一个虚拟机,并使用该镜像安装对应的Linux操作系统,安装好之后, ...

  4. Factoextra R Package: Easy Multivariate Data Analyses and Elegant Visualization

    factoextra is an R package making easy to extract and visualize the output of exploratory multivaria ...

  5. Extending sparklyr to Compute Cost for K-means on YARN Cluster with Spark ML Library

    Machine and statistical learning wizards are becoming more eager to perform analysis with Spark MLli ...

  6. RavenDB FS 安装使用 介绍

    前言 最近项目因为要存储图片和文件,折腾了RavenDB,使用RavenDB的FS系统统一管理图片和文件. 安装 RavenDB 的FS文件系统,需要用到windows的远程差分压缩功能: 安装好之后 ...

  7. loadrunner提高篇-结果分析实践

    分析图合并 一.分析图合并原理 选择view->merge graphs,弹出如图1所示对话框 图1(设置合并图) 1.选择要合并的图.选择一个要与当前活动图合并的图,注意这里只能选择X轴度量单 ...

  8. Java IO流之随机读写流RandomAccessFile

    随机读写流RandomAccessFile 简介 此类的实例支持对随机访问文件的**读取和写入**. 随机访问文件的行为类似存储在文件系统中的一个大型 byte 数组. 存在指向该隐含数组的光标或索引 ...

  9. 编码的秘密(python版)

    编码(python版) 最近在学习python的过程中,被不同的编码搞得有点晕,于是看了前人的留下的文档,加上自己的理解,准备写下来,分享给正在为编码苦苦了挣扎的你. 编码的概念 编码就是将信息从一种 ...

  10. scrapy调试时出现 ImportError: No module named win32api

    windows下利用scrapy(python2.7)写爬虫,运行 scrapy crawl dmoz 命令时提示:exceptions.ImportError: No module named wi ...