在aspx页面中显示图像 [英] Display Image in aspx page

查看:141
本文介绍了在aspx页面中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用HttpHandler的情况下从数据库中检索和显示aspx页面中的多个图像?

解决方案

这只是一个想法。



1.您可以将图像转储/保存到临时文件夹中,并将这些图像链接到转发器控件中。转发器控件具有图像模板。如果您担心临时图像,可以创建要删除的cronjob。



2.如果您不想将图像保存在临时文件夹中。您还可以将图像转换/编码为base64字符串,并将这些base64嵌入到html中。尝试搜索谷歌基础64图像的HTML。



3.你也可以创建一个我不推荐的大图像,并垂直绘制每个图像。



我通常使用第一种方法。如果你有cronjob的问题,你也可以使用CacheItem的OnRemoveCallback来删除临时图像。示例代码如下。

 受保护 无效 Page_Load( object  sender,EventArgs e)
{
string tempFilePath = C:\\ Imagepath \\\\ image1.jpg;

DeleteFile(tempFilePath);
}

private void DeleteFile( string fileName)
{
HttpContext.Current.Cache.Add(fileName,fileName, null
DateTime.Now.AddMinutes( 5 ),
Cache.NoSlidingExpiration,
CacheItemPriority.Normal,
(key,< span class =code-sdkkeyword> value ,reason)= >
{
尝试
{
File.Delete(Convert.ToString( value ));
}
catch {}
});

}




通过以下内容 -



SQL Database Image Storage&简易缩略图 [ ^ ]

How To Retrieve and display more than 1 images in aspx page from database without using HttpHandler??

解决方案

This is just an idea.

1. you can dump/save the images into the temporary folder and link those images into the repeater control. the repeater control has image template. if you worry about the temporary images, you can create cronjob to delete.

2. if you don't want to save the images in the temp folder. you can also convert/encode the images into base64 string and embed those base64 into the html. try to search in google "base 64 images in html".

3. you can also create a large image which I don't recommend, and draw each image vertically.

I usually use the 1st method. if you have a problem with the cronjob, you can also use the OnRemoveCallback of CacheItem to delete the temporary images. sample code below.

protected void Page_Load(object sender, EventArgs e)
{
    string tempFilePath = "C:\\Imagepath\\image1.jpg";

    DeleteFile(tempFilePath);
}

private void DeleteFile(string fileName)
{
    HttpContext.Current.Cache.Add(fileName, fileName, null,
                                  DateTime.Now.AddMinutes(5),
                                  Cache.NoSlidingExpiration,
                                  CacheItemPriority.Normal,
                                  (key, value, reason) =>
                                  {
                                      try
                                      {
                                          File.Delete(Convert.ToString(value));
                                      }
                                      catch { }
                                  });

}


Hi,
Go through the following-

SQL Database Image Storage & Easy Thumbnails[^]


这篇关于在aspx页面中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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