标题说明了一切,我有一个通用处理程序(.ashx)和一个只需要使用一个处理程序同时显示一个图像的处理程序。谢谢!我在我的项目中使用了asp.net和c#。我需要显示的所有图像都是动态生成的。我有一个网络用户控件,它使用这个处理程序来显示动态BitMap图像创建在一个asp图像控件。但是当我同时使用其中的两个WebControls时,我遇到了一个问题,因为这两个WebControl显示的是相同的图像。
ImageHandler.ashx (这些效果并不重要,它只是在用户选择下拉列表中的选项时改变图像,这不是真正的问题。)
public void ProcessRequest(HttpContext context)
{
string Effect = context.Request.QueryString["Effect"];
if (Effect == "Normal")
{
Bitmap bmp = PanelStepTwo.image;
context.Response.ContentType = "image/png";
bmp.Save(context.Response.OutputStream, ImageFormat.Png);
}
else if (Effect == "PB")
{
Bitmap bmp = PanelStepTwo.imagePB;
context.Response.ContentType = "image/png";
bmp.Save(context.Response.OutputStream, ImageFormat.Png);
}
else if (Effect == "Sepia")
{
Bitmap bmp = PanelStepTwo.imageSepia;
context.Response.ContentType = "image/png";
bmp.Save(context.Response.OutputStream, ImageFormat.Png);
}
}下面是处理程序的调用方式。(I是索引,因为它是在循环中调用的) Usuario.Imagensi返回一个URL,例如,如果'i‘是0,则Usuario.Imagens返回:@"http://edgeconstrutora.com.br/FotoFacil/Images/he0cy.png“
imgID = i;
var request = WebRequest.Create(Usuario.Imagens[i]);
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
image = new Bitmap(stream);
var ratioX = (double)120 / image.Width;
var ratioY = (double)120 / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
proporcao = image.Width / newWidth;
img.Width = newWidth;
img.Height = newHeight;
Effect = "Normal";
img.ImageUrl = "ImageHandler.ashx?imgID=" + imgID + "&Effect=" + Effect.ToString();
}发布于 2013-02-06 10:29:55
将IsReusable属性设置为true以处理多个图像。在我最后一次查看时,没有关于这一点的MSDN文档。但这是我用来显示的,比如说,产品图片的列表。
https://stackoverflow.com/questions/14720005
复制相似问题