⑴ 怎麼從資料庫里讀取保存的圖片文件
你存資料庫需要把位元組,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'];
?>