如何在数据库中以二进制格式显示图像 [英] how to display an image in gridview from database which is in Binary format

查看:78
本文介绍了如何在数据库中以二进制格式显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,





如何在二进制格式的数据库中以gridview显示图像..?



i使用MySql数据库

Hi Friends,,


How to display an image in gridview from database which is in Binary format..?

i am using MySql database

推荐答案

你必须使用通用处理程序。

请参阅 - 在数据库中显示GridView中的图像? [ ^ ]。



因此,在Gridview的DataBound事件中,您可以编写如下内容。

You have to use generic handler.
Refer - Showing image in GridView from the database?[^].

So, in DataBound event of Gridview you can write something like below.
Image1.ImageUrl = "~/ShowImage.ashx?id=" + id;



其中 Image1 是gridview中的图像控件, id 图像表中的员工ID之类的外键值(您可以在数据绑定时获取此信息)。



处理程序将返回整个图像,并将显示在th直接在图像控制。



更多参考:

1. 从数据库中保存并检索Binarydata到图像 [ ^ ]。

2. 如何在gridview中显示sql表中的图像? [ ^ ]


Where Image1 is the image control in the gridview and id is the Foreign Key value like "Employee ID" in Image Table (you can get this while databinding).

The handler will return you the whole image and will be shown in that image control directly.

More reference :
1. Save and retrive Binarydata from database into image[^].
2. how to display image from sql table in gridview?[^]


// Suppose you have image in grid like this

<img id="Img_1" src="GetImage.aspx" />

// create a new page "GetImage.aspx" and write the following code :

// load image binary from database like this :

byte[] bt = ((byte[])Ds.Tables[0].Rows[0]["dbimage"].ToString());
            
Response.Clear();
Response.ContentType = "image/x-icon";
Response.AddHeader("content-disposition", "inline;filename=image.jpg");
Response.Flush();
Response.BinaryWrite(bt);
Response.End();


这篇关于如何在数据库中以二进制格式显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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