導航:首頁 > 數據處理 > 資料庫中的圖片如何讀取

資料庫中的圖片如何讀取

發布時間:2022-11-29 15:39:20

⑴ 怎麼從資料庫里讀取保存的圖片文件

你存資料庫需要把位元組,nsdata都一起存進去才可以的,你是怎麼存的? 查看原帖>>

⑵ 如何將資料庫的圖片讀取到頁面中

樓上說的是添加圖片到資料庫的一種簡單點的方法,還有一種方法是把圖片添加到資料庫,並且把圖片保存到項目的文件夾中,最後在讀取出來。我這里有個例子,樓主可以參考
//上傳圖片調用的一個方法

bool CheckValidExt(string sExt)
{
bool flag = false;
string[] aExt = AllowExt.Split('|');
foreach (string filetype in aExt)
{
if (filetype.ToLower() == sExt.Replace(".", ""))
{
flag = true;
break;
}
}
return flag;
}

//上傳圖片
private void UploadPicFile(System.Web.UI.WebControls.FileUpload Fupload)
{
//文件上傳函數
if (fileBrowser.HasFile)
{
//fileBrowser是你上傳控制項的id名

string fullFileName = this.fileBrowser.FileName;//文件路徑名
//判斷文件格式
string sExt = fileBrowser.FileName.Substring(fileBrowser.FileName.LastIndexOf(".")).ToLower();
if (!CheckValidExt(sExt))
{
lblMsg.Text = "(原圖片文件格式不正確!支持的格式有[ " + AllowExt + " ])";
return;
}
//判斷文件大小
int intFileLength = fileBrowser.PostedFile.ContentLength;
if (intFileLength > 1000 * 1000)
{
this.lblMsg.Text = "文件大於1M,不能上傳!";
return;
}

string UpDir = "~/UserFile/123/"; //上傳目錄,圖片保存在項目的路徑
if (!Directory.Exists(Server.MapPath(UpDir)))
{
Directory.CreateDirectory(Server.MapPath(UpDir));
if (!Directory.Exists(Server.MapPath(UpDir)))
return; //如果創建失敗則返回
}
string fileName = Server.MapPath(UpDir) + this.fileBrowser.FileName;
fileBrowser.PostedFile.SaveAs(fileName);
}
else
lblMsg.Text = "請選擇文件!";
return;
}
internal readonly string AllowExt = "jpe|jpeg|jpg|png|tif|tiff|bmp|gif|wbmp|swf|psd";
前台讀取的話<img src='UserFile/123/<%# Eval("資料庫中保存圖片的欄位")%>'>

⑶ php中如何從資料庫中讀取圖片

比較普遍的方法是通過代碼實現。

⑷ 怎麼讀取資料庫中的圖片

確保你的圖片已經保存到資料庫,如果沒什麼錯誤,那就看下面
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="這是一張圖片" >

⑸ 資料庫以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

⑹ 如何才能往資料庫里讀取圖片數據或者從資料庫里讀圖片能告訴我具體步驟嗎謝謝

具體步驟:
1.連接資料庫
2.查詢資料庫
3.調用資料庫中的圖片(有些是按照地址保存,有的是按照二進制保存)
在調用的地方用<img src="<%=rs("存放圖片的欄位")%>">
這樣就可以了

⑺ 如何才能往資料庫里讀取圖片數據或者從資料庫里讀圖片

給你提供個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

⑻ 資料庫如何存儲圖片和取出圖片

思路是這樣的!你在個人資料裡面加個欄位
varchar類型的,用來保存圖片路徑。然後把圖片名稱保存到資料庫就行了,取的話就用Sql讀出圖片名稱,把要放置圖片的位置路徑寫好,名稱就用那個欄位拼下字元串就行了!我是學Java的。C#代碼不是很熟,思路就這樣的吧。我以前就這樣做的,你可以試下!

⑼ 如何從資料庫中讀取圖片,圖片存在文件夾中

我來回答你吧!我這些天碰到了和你一樣的問題,後來我解決了,我給你兩種方法。
方法一:圖片是直接存在SQL Server中的Image類型中的,你首先新建一個空白的aspx網頁,在這個新建的網頁的Page_Load()中讀出Image,然後用Response.BinaryWrite()函數顯示出來,然後在你原來的那個網頁中的Image控制項的ImageURL屬性填那個新建的aspx網頁,就是
image1.ImageUrl = "temp.aspx";這樣就好了
方法二:資料庫存的不是Image欄位,而是圖片的的地址,然後再Image的ImageURL中填這個地址就行了,直接能顯示出來。
我用的第二種方法,在我前幾天就這問題感到很迷茫的時候搜了很多資料,假如你還是不清楚就可以跟我說,我這段時間都在線!祝你好運!

⑽ 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'];
?>

閱讀全文

與資料庫中的圖片如何讀取相關的資料

熱點內容
聚多生活如何分享商品到小程序 瀏覽:302
新工資系統如何錄數據 瀏覽:20
如何調出電腦主程序界面 瀏覽:254
微波遙感採用什麼技術 瀏覽:516
三菱plc改程序怎麼寫 瀏覽:107
交易貓蘋果區如何填寫 瀏覽:887
武昌東湖技術開發區在哪裡 瀏覽:142
spss年級屬於什麼類型的數據 瀏覽:37
如何看好市場龍頭 瀏覽:296
如何申請水果交易平台 瀏覽:359
如何在釘釘上用小閑小程序查成績 瀏覽:767
柳州鐵道職業技術學院哪些專業可以專升本 瀏覽:140
ajax不返回數據怎麼辦 瀏覽:793
抖音小程序怎麼放在視頻下方 瀏覽:630
壞道硬碟的數據怎麼導出 瀏覽:932
昆明西山區玩具批發市場在哪裡 瀏覽:679
程序員發布會是什麼 瀏覽:629
如何讓小程序有黏性 瀏覽:983
碧水源屬於哪個交易所 瀏覽:312
二手房交易哪些證 瀏覽:381