标题:如何在VB的image控件中显示ACCESS的图片
只看楼主
jy02444572
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-3
 问题点数:0 回复次数:5 
如何在VB的image控件中显示ACCESS的图片
如何在VB的image控件中显示ACCESS的图片图片中ACCESS中的图片如何得到的
我看过很多书中介绍ACCESS中的图片是“包”,不能在VB的image控件中显示
现在在做毕业设计,有例子,那种二进制的图片可以显示
好心人能帮帮吗,谢谢拉

搜索更多相关主题的帖子: image控件 ACCESS 二进制 毕业设计 
2007-06-03 16:35
lulibo
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-1-17
得分:0 
Private Sub Command1_Click()
CommonDialog1.Filter = "(jpg文件).jpg|*.jpg" '选择要读入的图片
CommonDialog1.ShowOpen
Dim str As New ADODB.Stream
Dim sql As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
str.Type = adTypeBinary
str.Open
str.LoadFromFile CommonDialog1.FileName
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Persist Security Info=false;Data source=" & App.Path + "\pic.mdb"
rs.Open "select pic from info", conn, 1, 3
rs.AddNew
rs("pic") = str.Read '将图片读入到数据库
rs.Update
rs.Close
conn.Close
str.Close
End Sub
Private Sub Command2_Click() '显示图片按钮
Dim str As New ADODB.Stream
Dim sql As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Persist Security Info=false;Data source=" & App.Path + "\pic.mdb"
rs.Open "select pic from info", conn, 1, 1
rs.MoveLast
str.Mode = adModeReadWrite
str.Type = adTypeBinary
str.Open
str.Write rs("pic")
str.SaveToFile App.Path + "\test.jpg", adSaveCreateOverWrite '运行时会自动在目录下创立一个test.jpg空图片来存放要显示的图片
Image1.Picture = LoadPicture(App.Path + "\test.jpg")
End Sub
2007-06-07 13:09
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
得分:0 
Private Sub ShowPhoto(rf As ADODB.Field)
Dim Chunk() As Byte
Const ChunkSize As Integer = 2384
Dim DataFile As Integer, Chunks, Fragment As Integer
Dim MediaTemp As String
Dim lngOffset, lngTotalSize As Long
Dim i As Integer
MediaTemp = App.Path & "\picturetemp.tmp"
DataFile = 1
Open MediaTemp For Binary Access Write As DataFile
lngTotalSize = rf.ActualSize
Chunks = lngTotalSize \ ChunkSize
Fragment = lngTotalSize Mod ChunkSize
ReDim Chunk(Fragment)
Chunk() = rf.GetChunk(Fragment)
Put DataFile, , Chunk()
For i = 1 To Chunks
ReDim Chunk(ChunkSize)
Chunk() = rf.GetChunk(ChunkSize)
Put DataFile, , Chunk()
Next i
Close DataFile
Picture1.Picture = LoadPicture(MediaTemp)
Kill MediaTemp
End Sub

2007-06-07 15:02
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
得分:0 
If Not IsNull(rst.Fields("照片")) Then
ShowPhoto rst.Fields("照片")
Else
Picture1.Picture = LoadPicture("")
End If

2007-06-07 15:02
lulibo
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-1-17
得分:0 
心中有剑的做法是不可行的
2007-06-08 22:52
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
得分:0 
设置一下数据库字段的类型为ole类型
2007-06-08 23:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-144536-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.445534 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved