當前位置:首頁 » 操作系統 » 資料庫讀取圖片

資料庫讀取圖片

發布時間: 2022-02-28 14:24:17

『壹』 資料庫以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

『貳』 mysql資料庫讀取圖片

讀出二進制,轉化成流,然後write到頁面上 byte[] blob = userinfo.getPhoto(); if(blob!=null){ response.reset(); response.setContentType("image/"+dat);

『叄』 SQL資料庫中如何存儲圖片和讀取

要看你用哪種語言,但是流程都差不多。都是把圖片變成留,然後變成位元組數組,然後再保存到資料庫裡面去。存地址確實是個辦法,但是卻不實用。

『肆』 如何從資料庫中讀取圖片到picturebox中

用SqlDataReader讀取圖片數據,放到流中,Image對象從流載入數據到PictureBox。有三種方式讀取圖片,這三種方式都要求將SqlDataReader的默認行為設置為SequentialAccess。
1使用GetSqlBytes檢索varbinary(max)數據:
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
Stream s = new MemoryStream(); //創建一個以內存為後備存儲的流
SqlCommand command = connection.CreateCommand();
SqlDataReader reader = null;
try
{
command.CommandText = "SELECT LastName,Photo FROM dbo.Employees " +
" WHERE LastName=@LastName";
command.CommandType = CommandType.Text;
//聲明參數並賦值
SqlParameter parameter = new SqlParameter("@LastName", SqlDbType.NVarChar, 20);
parameter.Value = lastName;
command.Parameters.Add(parameter);
connection.Open();
//修改DataReader的默認行為,SequentialAccess按順序接收數據並立即載入
//CloseConnection指明關閉DataReader時,對資料庫的連接也關閉
reader = command.ExecuteReader(
CommandBehavior.SequentialAccess|CommandBehavior.CloseConnection);
if (reader.HasRows)
{
while (reader.Read())
{
//SequentialAccess要求按順序接收數據,先接受reader[0]
this.label1.Text = reader[0].ToString();
if (reader.IsDBNull(1)) //若列值為空返回
return;
else
{
//使用reader.GetSqlBytes獲取圖像數據
SqlBytes bytes = reader.GetSqlBytes(1);
using (Bitmap proctImage = new Bitmap(bytes.Stream))
{
//以gif格式保存在Stream流並顯示
proctImage.Save(s, System.Drawing.Imaging.ImageFormat.Gif);
this.pictureBox1.Image = System.Drawing.Image.FromStream(s);
} } }
}
else
MessageBox.Show("No records returned.");
2使用GetSqlBinary檢索數據:
reader = command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
SqlBinary binaryStream = reader.GetSqlBinary(0);
3使用GetValue檢索數據:
while (reader.Read())
{
//如果從 varbinary(max) 列讀數據
byte[] binaryData = (byte[])reader.GetValue(0);

//如果從 varchar(max)或nvarchar(max) 列讀數據
String stringData = (String)reader.GetValue(1);
}
詳細代碼見我的「王一博客」danyaody

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

王大偉,這題我不要了,你隨意認證,任意拒絕,我已舉報。

『陸』 急~如何讀取資料庫中的圖片

我從後台可以將圖片上傳到img中,但是前台卻無法將該圖片讀取在前台顯示
那位大俠知道的
幫幫忙
急用
實在是沒有辦法了

『柒』 怎麼從資料庫中調用圖片

以上回答值得學習,如果是顯示在頁面上可以利用一個空的窗體,把圖片的二進制流寫到這個空窗體中,然後讀這個窗體的流就得到了

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

資料庫存的是文件名和路徑,通過這個路徑和文件名來顯示圖片。

『玖』 從資料庫中讀取照片

SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();
SqlDataReader read = command.ExecuteReader();
byte[] bytes = (byte[])read["userportrait"];
MemoryStream stream = new MemoryStream(bytes);
BinaryFormatter translate = new BinaryFormatter();
picHost.Image = (Image)translate.Deserialize(stream);
直接復制的沒具體修改 這個是讀取的

『拾』 如何從sql資料庫內讀取圖片

何必要將圖片存入資料庫,存圖片路徑不是更好。你想一下,如果做一個購物網,都將圖片以二進制存入資料庫,從網頁讀取的時間不是更長,更沒效率。

熱點內容
c語言輸出笑臉 發布:2024-09-22 16:38:49 瀏覽:371
安卓手機腳本錄制 發布:2024-09-22 16:35:32 瀏覽:93
密碼箱裡面的鑰匙是什麼 發布:2024-09-22 16:25:16 瀏覽:549
源程序編譯連接可執行程序 發布:2024-09-22 16:21:19 瀏覽:60
如果安卓手機一直關機打不開怎麼辦 發布:2024-09-22 16:00:08 瀏覽:834
象棋游戲演算法 發布:2024-09-22 15:55:56 瀏覽:869
iphone備份密碼忘了怎麼辦 發布:2024-09-22 15:41:06 瀏覽:323
4歲編程貓 發布:2024-09-22 15:18:46 瀏覽:579
androidopencv教程 發布:2024-09-22 15:04:59 瀏覽:456
演算法頭腦 發布:2024-09-22 15:04:09 瀏覽:692