1

I have some icons stored in database (i don't want the client to lose his icons, that's why i don't store them on disk - and some 5KB png's are not a big deal) which I need to be displayed in a grid, from where a user can either delete one ore upload some others. I managed to display the icons in the grid by converting the binary image into its Base64 representation (on the server) like this: (part of my JsonHelper, which returns the ExtJs grid store Json from a DataTable)

if (dt.Columns[j].DataType == Type.GetType("System.Byte[]"))
{
   byte[] byteArray = (Byte[])rows[i][j];
   //tempStr is the Json string i am building
   tempStr = tempStr.Replace(dt.Columns[j].ToString().ToLower(),
             Convert.ToBase64String(byteArray, 0, byteArray.Length));
}

Then, on client side, in the grid I render the column icon like this:

renderIcon: function (value)
{
   return '<img src="data:image/jpeg;base64,' + value + '" style = "margin-left: 5px; height: 24px; width: 24px;"/>';
}

Everything works fine, but it seems to me it is not an elegant way (for example, if i want to select an icon from the grid and put it in a container, i have to add a label in that container with a html that 'points' to the image, since I don't have an actual image to work with an img xtype)

Can this be done in an more elegant/proper way ? I am using ExtJs 4.0.7, SQL server 2008 with asp.net.

4

2 回答 2

2

由于您使用的是 ASP.NET,因此最简单的方法是创建 ashx 处理程序。示例实现可以在 - Display Image using ashx Handler中找到

使用 ashx 处理程序,您可以在图像的源中提供 URL。

于 2013-10-12T06:27:38.417 回答
0

您将图像名称保存在应用程序数据库中并创建一个获取请求表单服务器以显示您想要显示的图像。

于 2013-10-14T06:09:10.510 回答