① 如何才能往資料庫里讀取圖片數據或者從資料庫里讀圖片
給你提供個ACCESS版的VB代碼,使用時調用這些過程即可:
'使用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
② 怎樣讀取資料庫中存儲的二進制圖片文件
下面我們將示例一個圖片文件讀取存儲至資料庫並從資料庫中讀取圖片信息並顯示的案例:
1、首先讀取硬碟上的某一具體圖片文件,讀取模式設置為readBinary方式:
<cffile
action
=
"readBinary"
file
=
"temp
directory
here#file.serverFile#"
variable
=
"test">
2、將讀取出來的二進制內容存儲至資料庫中(註:資料庫欄位需設置成能存儲圖片類型的欄位,如blob類型):
<cfquery
datasource
=
"datasource">
insert
into
imageTest
values
(<cfqueryparam
cfsqltype="cf_sql_blob"
value="#test#">)
</cfquery>
通過1、2兩個步驟,我們輕松實現了讀取圖片文件並存儲至資料庫的操作過程。
3、從資料庫中讀取圖片信息,該文件可命名為dispImage.cfm:
<!---
在此需特別注意enablecfoutputonly的壓縮空白功能,如果不對該頁面進行空白壓縮,很可能會造成圖片無法顯示的問題
--->
<cfprocessingdirective
suppressWhiteSpace="yes">
<cfsetting
enablecfoutputonly="yes">
<!---
讀取相應的圖片信息
--->
<cfquery
datasource
=
"datasource">
select
image
from
imageTest
where
variable
here#
</cfquery>
<!---
設置瀏覽器輸出的格式,我們將它設置為圖片的JPG類型,用戶可根據實際情況改動類型設置
--->
<cfcontent
type="image/jpg">
<!---
輸出圖片
--->
<cfoutput>#toString(imageTest.image)#</cfoutput>
</cfprocessingdirective>
<cfabort>
4、顯示圖片內容,調用dispImage.cfm頁面:
<img
src
=
"dispImage.cfm?id=your
variable
here">
通過3、4兩個步驟,我們也很容易的就完成了從資料庫中讀取圖片信息並在頁面顯示的功能。
總結:實際上,除了圖片文件可以如此處理,其它的文件也能通過類似方式進行處理,可將任意文件類型存儲至資料庫,只是文件大小的原因以及資料庫存儲讀取速度性能限制,我們基本上還是不建議將文件存儲至資料庫,畢竟硬碟讀取要快得多。
③ 資料庫以img存儲,如何讀取圖片
直接使用企業管理器好像沒有辦法操作吧,通過軟體或自己做個小軟體讀取。
#region //讀取資料庫中圖片到內存.並顯示
public void LoadToMemoryAndDisable(string serverAdress, string database)
{
//讀取資料庫中圖片到內存.並顯示
SqlConnection conn = new SqlConnection("server=" + serverAdress + ";integrated security = sspi;database = " + database);
SqlCommand cmd = new SqlCommand("select * from imgtable where imgname like '%bmp%'", conn);
conn.Open();
SqlDataReader dr;
try
{
dr = cmd.ExecuteReader();
dr.Read();
System.Data.SqlTypes.SqlBinary sb = dr.GetSqlBinary(2);
//或byte[] imageData = (byte[])dr[2];
MemoryStream ms = new MemoryStream(sb.Value);//在內存中操作圖片數據
Bitmap bmp = new Bitmap(Bitmap.FromStream(ms));
this.pictureBox1.Image = bmp;
dr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
#endregion
④ 怎麼們把資料庫中的圖片讀出來我用的是DW+ACCESS資料庫,下面是細節,跪求!在線等!!
你要不這么寫試試 src="loap_pics/"+<%=(Recordset1.Fields.Item('up_pic').Value)%>或者src="loap_pics/<%=(Recordset1.Fields.Item('up_pic').Value)%>"
⑤ 急~如何讀取資料庫中的圖片
資料庫中只保存一個圖片目錄,直接存儲圖片於資料庫中會導致性能低下的
⑥ php中如何從資料庫中讀取圖片
<?php
//將圖片存進資料庫再讀出,注意存儲圖片的欄位類型必須為blob
$user=』root』;
$password=』root』;
$db=』test』;
$connect=mysql_connect(『localhost』,$user,$password);
mysql_set_charset(『utf8′,$connect);
mysql_select_db($db);
$photo = 「0x」.bin2hex(file_get_contents(「./test.jpg」));
$sql=」INSERT INTO `test`.`test` (`photo`) VALUES ($photo);」;//$photo不需要用引號,切記
mysql_query($sql);
//$result=mysql_query(「SELECT *
//FROM `test`
//LIMIT 0 , 30〃);
//$img=mysql_fetch_array($result);
//echo $img['photo'];
?>
⑦ 怎麼讀取資料庫中的圖片
確保你的圖片已經保存到資料庫,如果沒什麼錯誤,那就看下面
showming.asp
<!--#include file="../conn/conn1.asp" --> '連接資料庫
<%
id=clng(trim(request("id")))
if id="" then response.End
response.Expires=0
response.buffer=true
response.Clear()
set rs=server.CreateObject("adodb.recordset")
sql="select * from proct where proctid="&id&""
rs.open sql,conn,3,1
response.ContentType="image/*"
response.BinaryWrite rs("photo")
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
顯示的圖片的頁面:picshow.asp
<img src="showimg.asp?id=<%=rs("proctid")%>" width="400" height="300" border="0" alt="這是一張圖片" >
⑧ 如何將資料庫中存儲的圖片(不是圖片路徑) 讀取並顯示
讀取的話,先從資料庫取出來,然後..
sqlcon = new SqlConnection(con);
string sss = "select * from ppp";
sqlada = new SqlDataAdapter(sss,sqlcon);
myset.Clear();
sqlada.Fill(myset);
MemoryStream ms = new MemoryStream((Byte[])(myset.Tables[0].Rows[2]["photodata"]));
this.pictureBox1.Image = Image.FromStream(ms);
⑨ php中如何從資料庫中讀取圖片
資料庫中存的只是圖片的路徑,圖片放在相應的文件夾下,跟讀取其它的內容一樣直接輸出來讀取就可以了,讀到路徑後用<img>標簽就可以顯示圖片
⑩ 如何才能往資料庫里讀取圖片數據或者從資料庫里讀圖片能告訴我具體步驟嗎謝謝
具體步驟:
1.連接資料庫
2.查詢資料庫
3.調用資料庫中的圖片(有些是按照地址保存,有的是按照二進制保存)
在調用的地方用<img src="<%=rs("存放圖片的欄位")%>">
這樣就可以了