VB里怎么编程保存图片

VB里怎么编程保存图片,比如图片框里的... VB里怎么编程保存图片,比如图片框里的 展开
 我来答
匿名用户
2013-10-21
展开全部
给你个ADO对象操作的例子,你仿照着做就是了:

'使用ADODB.Stream来保存/读取文件到数据库
'引用Microsoft ActiveX Data Objects 2.5 Library及以上版本

'保存文件到数据库中
Sub SaveFile()
Dim Stm As New ADODB.Stream
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCnn As String

strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & _
App.Path & "\DB1.mdb"
Cnn.Open strCnn

'读取文件到内存(二进制模式)
With Stm
.Type = adTypeBinary
.Open
.LoadFromFile App.Path + "\Image1.bmp"
End With

With rs
.Open "SELECT * FROM TABLE1", Cnn, 1, 3
.AddNew
.Fields("IMAGE") = Stm.Read
.Update
End With

rs.Close
Stm.Close
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub

Sub ReadFile()
Dim Stm As New ADODB.Stream
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCnn As String

strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & _
App.Path & "\DB1.mdb"
Cnn.Open strCnn
rs.Open "SELECT IMAGE FROM TABLE1 WHERE ID = 18", Cnn, adOpenKeyset, adLockReadOnly

'保存到文件
With Stm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write rs("IMAGE")
.SaveToFile App.Path + "\Image2.bmp"
End With

'显示图片
Picture1.Picture = LoadPicture(App.Path + "\Image2.bmp")

rs.Close
Stm.Close
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式