将二进制图片转换为普通图片?(来自数据库) [英] converting a binary picture into a normal pic?(from database)

查看:106
本文介绍了将二进制图片转换为普通图片?(来自数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,基本上,目前我将图片存储到数据库中,该数据库是我用一些信息(例如产品ID,名称等)制成的,并且还带有图像.我正在使用列表中可用的上传功能并对其进行配置.因此,当我尝试显示数据库中的图片时,它将显示System.Byte [].有什么显示方式吗?如图所示,而不是显示的字节数?

谢谢您的事先帮助:-D

Well basically, currently i stored a picture into a database which i made with some info, like product id, name, etc etc and also an image together with it. Im using the upload feature which is available in the list and configured it. So when i try to display the picture from the database, it shows System.Byte[]. Is there any way to display it?as in the picture instead of the number of bytes there is?

Thank you for your help in advance :-D

推荐答案

要在数据库中的Web表单上显示图像,您已经创建了一个页面.此页面将从数据库中获取图像,然后您必须提供该页面的图像URL.

例子

这是imageDisplay页面,而DisplayPage是将在页面加载时调用的方法.
受保护的void DisplayImage(long UserID)
{
CreateConnection(); //创建连接
SqlCommand cmd =新的SqlCommand();
cmd.Connection = con;
cmd.CommandText =从tbl_Member中选择照片,其中UserID =" + UserID;
SqlDataReader rd = cmd.ExecuteReader();
如果(rd.HasRows)
{
while(rd.Read())
{
如果(!rd.IsDBNull(0))
{
Response.ContentType ="image/gif";
Response.BinaryWrite((byte [])rd [0]);
}
}

}
CloseConnection();
}



现在将ImageUrl属性提供给Image控件,您想在哪里显示图像.作为

imPhoto.ImageUrl ="ImageDisplay.aspx?UserID =" + long.Parse(Request.QueryString ["UserID"].ToString());
To display a Image on web form from database you have create a page. this page will fetch image from database then you have to give image url of that page.

example

this is imageDisplay page and DisplayPage is method which will call on page load..

protected void DisplayImage(long UserID)
{
CreateConnection(); // creating connection
SqlCommand cmd = new SqlCommand();
cmd.Connection=con;
cmd.CommandText = "Select photo from tbl_Member where UserID=" + UserID;
SqlDataReader rd = cmd.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{
if (!rd.IsDBNull(0))
{
Response.ContentType = "image/gif";
Response.BinaryWrite((byte[])rd[0]);
}
}

}
CloseConnection();
}



now give ImageUrl properties to Image control where do u want to display image. as

imPhoto.ImageUrl = "ImageDisplay.aspx?UserID=" + long.Parse(Request.QueryString["UserID"].ToString());


这篇关于将二进制图片转换为普通图片?(来自数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆