繁体   English   中英

ASHX图像处理程序随机显示/隐藏图像

[英]ASHX Image Handler randomly showing/hiding images

我构建了ASHX图像处理程序,它提取了存储在SQL Server中的图像。 如果我单独显示图像,它的效果很好。 但是,如果我尝试在Grid中显示它们并同时显示许多图片,则某些图片将不会随机显示。

当我尝试刷新页面时,某些图像消失,而另一些图像再次出现。 它完全随机地渲染图像。 请查看下面的图片以获得4个屏幕截图。

在此处输入图片说明

以下是我的处理程序代码。 我试图更改IsReusable是非,但没有运气。 您能告诉我如何解决这个问题吗? 谢谢。

public class Photo : IHttpHandler
{

    #region IHttpHandler Members

    public bool IsReusable
    {            
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        HttpRequest request = context.Request;

        if (!string.IsNullOrEmpty(request.QueryString["id"]) && !string.IsNullOrEmpty(request.QueryString["type"]))
        {
            //this hash table contain the SP parameter
            DAMSSQL db = DAMSSQL.GetInstance("DBName");

            SqlCommand cmd = new SqlCommand("dbo.GetImage");
            cmd.Parameters.Add("@ID", SqlDbType.Int).Value = int.Parse(request.QueryString["id"]);
            cmd.Parameters.Add("@Type", SqlDbType.Int).Value = int.Parse(request.QueryString["type"]);

            object obj = db.ExecuteScalar(cmd);

            if (obj != null)
            {
                byte[] imageArray = (byte[])obj;

                //checking byte[] 
                if (imageArray != null && imageArray.Length > 0)
                {   
                    context.Response.ContentType = "image/jpeg";
                    context.Response.BinaryWrite(imageArray);
                }
            }
            else
            {   
                context.Response.StatusCode = 404;
                context.Response.StatusDescription = "The requested image is not found in the system.";
                context.Response.End();

            }
        }
        else
        {
            context.Response.StatusCode = 500;
            context.Response.StatusDescription = "The incoming parameters are not correct.";
            context.Response.End();                
        }
    }

    #endregion
}

我在这里问了类似的问题:

使用HttpHandler流式处理数据库图像

我最终改用了DataReader,它解决了我的问题,而不是全部渲染图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM