如何显示SQL SERVER中的图像

WUNEN 2008-03-25 09:37:43
图像字段为:CARPHOTO
取ID字段的值直接用rs("ID")即可,请问如何把CARPHOTO字段中的图像读出来放到Picture1中,先谢谢
...全文
26 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
WUNEN 2008-03-25
问题解决,结贴
回复
WUNEN 2008-03-25
TO 2楼,图片有什么办法可压缩一下?太大了,因为我还要对它加字上去呢
回复
WUNEN 2008-03-25
放心吧,只要解决问题,分是小事,先谢了
回复
记得给分,吼吼
回复
读取的
Private Sub ReadFromDB(RY As String)
Dim Rst As New ADODB.Recordset
Dim Mstream As ADODB.Stream
Dim SQL As String

On Error Resume Next


SQL = "select * from ry_manage where rybh='" & RY & "'"
Set Rst = New ADODB.Recordset
Rst.CursorLocation = adUseClient
Rst.Open SQL, Conn, adOpenStatic, adLockReadOnly, adCmdText

If IsNull(Rst.Fields("pic")) Then img.Picture = LoadPicture(): Exit Sub

If Rst.RecordCount = 0 Then
ShowMsg 1, " 数据库出错,请与系统管理员联系!"
Rst.Close
Set Rst = Nothing
Exit Sub
End If

Set Mstream = New ADODB.Stream
Mstream.Type = adTypeBinary
Mstream.Open
Mstream.Write Rst.Fields("pic").Value
Mstream.SaveToFile App.Path & "\tmpImage.gif", adSaveCreateOverWrite
Mstream.Close
Set Mstream = Nothing
img.Picture = LoadPicture(App.Path & "\tmpImage.gif")

End Sub

保存的
Private Sub SaveToDB(RY As String)
Dim Rst As New ADODB.Recordset
Dim Mstream As New ADODB.Stream
Dim SQL As String
Dim MediaName As String

MediaName = Trim$(PicFileName)


Set Rst = New ADODB.Recordset
Rst.CursorLocation = adUseClient
SQL = "select * from ry_manage where rybh='" & RY & "'"
Rst.Open SQL, Conn, adOpenStatic, adLockPessimistic, adCmdText

Set Mstream = New ADODB.Stream
Mstream.Type = adTypeBinary
Mstream.Open

Mstream.LoadFromFile PicFileName
Rst.Fields("Pic").Value = Mstream.Read
Rst.Update

Rst.Close
Set Rst = Nothing
Set Mstream = Nothing

End Sub
回复
Tiger_Zhao 2008-03-25
用 rs("CARPHOTO").GetChunk 取得二进制数据,具体调用参考 MSDN。
如果二进制内容就是图片内容,那么存成文件,LoadPicture就可以了;如果是其它格式就要根据格式进行处理了。
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-03-25 09:37
社区公告
暂无公告