是否可以同时显示一个处理程序中的多个图像

本文关键字:程序 处理 一个 图像 是否 显示 | 更新日期: 2023-09-27 17:57:44

标题说,everithing,我有一个Generic Handler(.ashx)和一个。我需要同时使用一个处理程序显示一个图像。谢谢你!我在我的项目中使用asp.net和c#。我需要显示的所有图像都是动态生成的。我有一个Web用户控件,它使用这个处理程序来动态显示在asp图像控件上创建的BitMap图像。但是,当我同时使用其中两个WebControl时,我会遇到问题,因为两个Web控件都显示相同的图像。

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是索引,因为它是在循环中调用的)高利贷。Imagens[i]返回一个URL,例如,如果"i"是0,Usuario。Imagens[0]返回:@"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();
}

是否可以同时显示一个处理程序中的多个图像

将IsReusable属性设置为true以处理多个图像。上次我看的时候没有MSDN文档。但这就是我用来显示的东西,比如说,产品图片列表。