问题描述
我想在我的.aspx页面中显示二进制格式图像。
我正在使用asp.net,C#和ms sql 2005数据库。
我可以将图像存储到数据库图像格式中。但我不能在图像中显示它。
我可以在变量中检索图像格式值,但不能在may图像中显示它。
这是我的代码...
Hi,
I want to show a binary format image in my .aspx page.
I am using asp.net,C# and ms sql 2005 database.
I can store am image into database image format filed. but i cant not show it in image.
I can retrieve the image format value in a variable but cant show it in may image.
this is my code...
byte[] img = (byte[])dt.Rows[0]["logo"];
Image1.ImageUrl = "~/" + img + "";
可以任意一个帮帮我??
提前感谢。
Rashed
can any one help me??
thanks in advance.
Rashed
推荐答案
using System;
using System.Web;
public class ImageHandler : IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.BinaryWrite(yourImageByte);// You must replace "yourImageByte" with image reader logic from database.
}
public bool IsReusable {
get { return false; }
}
}
最后你可以将图像绑定到处理程序。 />
Finally you can bind the image to the handler.
Image1.ImageUrl ="ImageHanderl.ashx"
欲了解更多信息,请查看 [] article。
For more information look this[^] article.
byte[] img = (byte[])dt.Rows[0]["logo"];
string s = System.Text.Encoding.ASCII.GetString(img);
Image1.ImageUrl = "~/" + s;
如果是内容,则稍微复杂一点。
忘记将img更改为s在最后一行 - OriginalGriff [/ edit]
If it is the content, then it is slightly more complex.
[edit]Forgot to change "img" to "s" in final line - OriginalGriff[/edit]
MemoryStream ms = new MemoryStream(img);
Image1 = Image.FromStream(ms);
信用这个:
[]
:D
Credit goes to this:
http://www.codeproject.com/Members/d-nish?msg=3367481#xx3367481xx[^]
:D
这篇关于从数据库显示二进制格式的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!