请教图片存入SQL后再提出后变大的问题
我的图片存储系统中,将图片转为流文件存入QSL的image属性字段中,现在上传与下载都没问题,但存入大量图片后,发现SQL数据库增大异常,几百M的图片到数据库变成了几个G,又发现下载后的图片(将流文件提出来)比存入进去时增大数倍(7-10倍左右)
请教大大们应如何解决以上问题??
存入代码:
strSQL = "SELECT 主表id,图片大小,图片名称,图片,图片属性,图片尺寸 FROM Hdp WHERE id=0"
Set rs = QueryExt(strSQL)
Set stm = New ADODB.Stream '设置ADO流文件
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile (Daa) '将文件转换为二进制数据流
rs.AddNew
rs(0) = x
rs(1) = a
rs(2) = TPSX
rs(3) = stm.Read '设置记录集为流文件
rs(4) = Z
rs(5) = Dcc
rs.Update '保存记录集
Set stm = Nothing
下载代码:
Dim rs As ADODB.Recordset
strSQL = "SELECT 图片大小,图片名称,图片 FROM Hdp WHERE id=" & QA2
Set rs = QueryExt(strSQL)
Label1.Caption = Mgoyc(rs(1))
Label2.Caption = rs(0)
Set Image1.DataSource = rs
Image1.DataField = "图片"
Set rs = Nothing
SavePicture Image1.Picture, strTemp '控件图片另存为
MsgBox "图片导出成功!", vbInformation + vbOKOnly, "提示"
[解决办法]
SavePicture 出的图片为bmp格式,当然比jpg大的多,要转换为下
[解决办法]
vb+access二进制存储和读取图片
Option ExplicitDim cnnP As ADODB.ConnectionDim adoP As ADODB.RecordsetDim mstP As ADODB.StreamDim strBMPFile As String'导入Sub import() Set cnnP = New ADODB.Connection cnnP.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb" & ";" Set adoP = New ADODB.Recordset adoP.Open "Select * From TB_BMP", cnnP, adOpenKeyset, adLockOptimistic Set mstP = New ADODB.Stream mstP.Type = adTypeBinary mstP.Open With cdlP .DialogTitle = "选取要存入的图片" .InitDir = App.Path .Filter = "位图文件 (*.bmp)|*.bmp" .ShowOpen strBMPFile = .filename End With If strBMPFile = "" Then Exit Sub mstP.LoadFromFile strBMPFile Label1.Caption = .FoundFiles.Item(i) mstP.LoadFromFile .FoundFiles.Item(i) adoP.AddNew adoP.Fields("FD_BMP").Value = mstP.Read adoP.Update adoP.Close cnnP.CloseEnd Sub'导出Sub export() Set cnnP = New ADODB.Connection cnnP.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb" & ";" Set adoP = New ADODB.Recordset adoP.Open "Select * From TB_BMP", cnnP, adOpenKeyset, adLockOptimistic Set mstP = New ADODB.Stream mstP.Type = adTypeBinary mstP.Open mstP.Position = 0 mstP.Write adoP!FD_BMP' Debug.Print adoP!FD_BMP mstP.SaveToFile App.Path & "\temp.bmp", adSaveCreateOverWrite Picture1.Picture = LoadPicture(App.Path & "\temp.bmp") mstP.Close adoP.Close cnnP.CloseEnd Sub
[解决办法]
加载到Image控件中再保存,是保存成BMP格式了,肯定会变成。
建议直接以二进制流的方式保存成文件之后,再用Image控件显示。就不会变大了