vb6如何使用png图片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb6如何使用png图片相关的知识,希望对你有一定的参考价值。
因为转化为gif,图片效果不好,,,,,我用ps做了一个按钮,想用mousemove事件,,,
有没有什么控件可以直接用的,,,,
Private Sub Form_Load()
Dim Token As Long
Dim C As Long
C = Me.BackColor
If C < 0 Then C = GetSysColor(C - &H80000000)
Token = InitGDIPlus
Picture1(0).Picture = LoadPictureGDIPlus(App.Path & "\1.png", , , vbWhite)
Picture1(1).Picture = LoadPictureGDIPlus(App.Path & "\1.png", , , vbCyan)
Picture1(2).Picture = LoadPictureGDIPlus(App.Path & "\1.png", , , vbGreen)
Picture1(3).Picture = LoadPictureGDIPlus(App.Path & "\1.png", , , C)
Image1.Picture = LoadPictureGDIPlus(App.Path & "\1.png", , , C)
FreeGDIPlus Token
End Sub 参考技术B Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type PICTDESC
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, _
inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
Private Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" (ByVal filename As Long, bitmap As Long) As Long
Private Declare Function GdipCreateHBITMAPFromBitmap Lib "GDIPlus" (ByVal bitmap As Long, _
hbmReturn As Long, ByVal background As Long) As Long
Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal image As Long) As Long
Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PICTDESC, _
RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Public Function LoadImage(ByVal strFName As String) As IPicture
Dim uGdiInput As GdiplusStartupInput
Dim hGdiPlus As Long
Dim hGdiImage As Long
Dim hBitmap As Long
uGdiInput.GdiplusVersion = 1
If GdiplusStartup(hGdiPlus, uGdiInput) = 0 Then
If GdipCreateBitmapFromFile(StrPtr(strFName), hGdiImage) = 0 Then
GdipCreateHBITMAPFromBitmap hGdiImage, hBitmap, 0
Set LoadImage = ConvertToIPicture(hBitmap)
GdipDisposeImage hGdiImage
End If
GdiplusShutdown hGdiPlus
End If
End Function
Public Function ConvertToIPicture(ByVal hPic As Long) As IPicture
Dim uPicInfo As PICTDESC
Dim IID_IDispatch As GUID
Dim IPic As IPicture
Const PICTYPE_BITMAP = 1
With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
With uPicInfo
.Size = Len(uPicInfo)
.Type = PICTYPE_BITMAP
.hPic = hPic
.hPal = 0
End With
OleCreatePictureIndirect uPicInfo, IID_IDispatch, True, IPic
Set ConvertToIPicture = IPic
End Function
vb.net 如何让datagridview添加图片列
先把需要添加图片的列样式改为 DataGridViewLabelXColumnDim bcx As DataGridViewLabelXColumn = TryCast(DataGridViewX1.Columns("列名"), DataGridViewLabelXColumn)
bcx.Image = ImageList1.Images("图片名")
会在文字前面填上你的图片 参考技术A DataGridView1.CurrentRow.Cells(11) = New DataGridViewCheckBoxCell 用这个DataGridBoolColumn用这个指定一列为复选框 参考技术B DataGridView控件显示图片文件的注意事项
来源: 发布时间:2010-03-23 浏览: 704 人次 字体:[大 中 小]
DataGridView控件中显示图片及其注意事项,windows Forms编程里面有一个DataGridView控件,它不光是可以显示数据,可以显示按钮,复选框,甚至还可以显示图片。这些图片可以来自于数据库(用二进制的方式存储的),也可以来自文件系统。下面是一个例子
【假设你有一个Winform程序,并且窗体上有一个DataGridView控件,这个控件只有一个列(名称为Image),类型为DataGridViewImageColumn】
public Form1()
InitializeComponent();
GetData();
private void GetData()
foreach (string s in Directory.GetFiles(@"E:\My Documents\图片收藏\表情","*.gif"))
this.demoGrid.Rows.Add(s);//注意,虽然字段类型是Image,但我们这里只给它传一个图片路径过去,真正读取图片是由下面的事件处理程序做的
/// <summary>
/// 这个事件就在尝试对单元格进行格式化的时候触发。在这里设置真正的图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void demoGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
if (demoGrid.Columns[e.ColumnIndex].Name.Equals("Image"))
string path = e.Value.ToString();
e.Value = GetImage(path);
public System.Drawing.Image GetImage(string path)
return System.Drawing.Image.FromFile(path);
以上的代码确实可以实现我们的目的,就是从一个目录中把所有的gif图片读取出来,然后显示在DataGridView上面。
以上是关于vb6如何使用png图片的主要内容,如果未能解决你的问题,请参考以下文章