当前位置:首页 » 操作系统 » 数据库怎么读取图片

数据库怎么读取图片

发布时间: 2022-04-17 17:06:59

数据库以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、首先读取硬盘上的某一具体图片文件,读取模式设置为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两个步骤,我们也很容易的就完成了从数据库中读取图片信息并在页面显示的功能。
总结:实际上,除了图片文件可以如此处理,其它的文件也能通过类似方式进行处理,可将任意文件类型存储至数据库,只是文件大小的原因以及数据库存储读取速度性能限制,我们基本上还是不建议将文件存储至数据库,毕竟硬盘读取要快得多。

⑶ 怎样从SQL数据库中读取图片,将他存为文件

Public Function ReadFromDb(ByRef conn As ADODB.Connection, ByVal strTbl As String, ByVal strFl As String, ByVal strCondi As String) As Boolean
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "select top 1 * from " & strTbl & " where " & strCondi, conn, 3, 2
If rs.EOF Or IsNull(rs(strFl)) Then
ReadFromDb = False
Exit Function
End If

Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields(strFl).Value
mstream.SaveToFile "c:\carrot.gif", adSaveCreateOverWrite
rs.Close
ReadFromDb = True
End Function

⑷ 如何才能往数据库里读取图片数据或者从数据库里读图片能告诉我具体步骤吗谢谢

具体步骤:
1.连接数据库
2.查询数据库
3.调用数据库中的图片(有些是按照地址保存,有的是按照二进制保存)
在调用的地方用<img src="<%=rs("存放图片的字段")%>">
这样就可以了

⑸ 从数据库中读取照片

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);
直接复制的没具体修改 这个是读取的

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

⑺ 图片怎么从数据库里读取出来

推荐你先看这篇文章:
使用asp.net将图片上传并存入SqlServer中,然后从SqlServer中读取并显示出来
一,上传并存入SqlServer
数据库结构
create table test
{
id identity(1,1),
FImage image
}
相关的存储过程
Create proc UpdateImage
(
@UpdateImage Image
)
As
Insert Into test(FImage) values(@UpdateImage)
GO

在UpPhoto.aspx文件中添加如下:
<input id="UpPhoto" name="UpPhoto" runat="server" type="file">
<asp:Button id="btnAdd" name="btnAdd" runat="server" Text="上传"></asp:Button>

然后在后置代码文件UpPhoto.aspx.cs添加btnAdd按钮的单击事件处理代码:
private void btnAdd_Click(object sender, System.EventArgs e)
{
//获得图象并把图象转换为byte[]
HttpPostedFile upPhoto=UpPhoto.PostedFile;
int upPhotoLength=upPhoto.ContentLength;
byte[] PhotoArray=new Byte[upPhotoLength];
Stream PhotoStream=upPhoto.InputStream;
PhotoStream.Read(PhotoArray,0,upPhotoLength);

//连接数据库
SqlConnection conn=new SqlConnection();
conn.ConnectionString="Data Source=localhost;Database=test;User Id=sa;Pwd=sa";

SqlCommand cmd=new SqlCommand("UpdateImage",conn);
cmd.CommandType=CommandType.StoredProcere;

cmd.Parameters.Add("@UpdateImage",SqlDbType.Image);
cmd.Parameters["@UpdateImage"].Value=PhotoArray;

//如果你希望不使用存储过程来添加图片把上面四句代码改为:
//string strSql="Insert into test(FImage) values(@FImage)";
//SqlCommand cmd=new SqlCommand(strSql,conn);
//cmd.Parameters.Add("@FImage",SqlDbType.Image);
//cmd.Parameters["@FImage"].Value=PhotoArray;

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}

二,从SqlServer中读取并显示出来
在需要显示图片的地方添加如下代码:
<asp:image id="imgPhoto" runat="server" ImageUrl="ShowPhoto.aspx"></asp:image>

ShowPhoto.aspx主体代码:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
SqlConnection conn=new SqlConnection()
conn.ConnectionString="Data Source=localhost;Database=test;User Id=sa;Pwd=sa";

string strSql="select * from test where id=2";//这里假设获取id为2的图片
SqlCommand cmd=new SqlCommand()
reader.Read();
Response.ContentType="application/octet-stream";
Response.BinaryWrite((Byte[])reader["FImage"]);
Response.End();
reader.Close();
}
}

⑻ mysql数据库读取图片

读出二进制,转化成流,然后write到页面上 byte[] blob = userinfo.getPhoto(); if(blob!=null){ response.reset(); response.setContentType("image/"+dat);

⑼ 如何才能往数据库里读取图片数据或者从数据库里读图片

王大伟,这题我不要了,你随意认证,任意拒绝,我已举报。

热点内容
服务器如何查看线程池未关闭 发布:2024-09-30 07:13:51 浏览:412
如何配置资源管理 发布:2024-09-30 07:08:10 浏览:992
坦克世界亚服服务器怎么连接 发布:2024-09-30 07:07:18 浏览:493
手机nba2k17的文件夹 发布:2024-09-30 06:50:30 浏览:898
广州市java培训 发布:2024-09-30 06:48:52 浏览:143
python爬虫简历模板 发布:2024-09-30 06:40:23 浏览:590
项目源码丢失反编译 发布:2024-09-30 06:27:07 浏览:776
fpga编译后生成什么文件 发布:2024-09-30 06:18:34 浏览:111
端编程语言 发布:2024-09-30 06:13:19 浏览:423
xp数据库 发布:2024-09-30 06:02:56 浏览:539