首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以同时显示处理程序中的多个图像?

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

Stack Overflow用户
提问于 2013-02-06 09:20:00
回答 1查看 1.2K关注 0票数 0

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

ImageHandler.ashx (这些效果并不重要,它只是在用户选择下拉列表中的选项时改变图像,这不是真正的问题。)

代码语言:javascript
复制
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“

代码语言:javascript
复制
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();
}
EN

回答 1

Stack Overflow用户

发布于 2013-02-06 10:29:55

将IsReusable属性设置为true以处理多个图像。在我最后一次查看时,没有关于这一点的MSDN文档。但这是我用来显示的,比如说,产品图片的列表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14720005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档