当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponse.WriteFile方法代码示例

本文整理汇总了C#中HttpResponse.WriteFile方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.WriteFile方法的具体用法?C# HttpResponse.WriteFile怎么用?C# HttpResponse.WriteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpResponse的用法示例。


在下文中一共展示了HttpResponse.WriteFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessImage

    private void ProcessImage(HttpApplication app, HttpResponse Response, HttpRequest Request)
    {
        string file = Request.Path.Substring(4).ToLower(); // stripping out the /cms part ...

        string output = "";

        Response.Clear();
        Response.ContentType = GetContentTypeOfFile(file);

        int newWidth = 0;
        int newHeight = 0;
        int maxWidth = 0;
        int maxHeight = 0;

        if (Request["w"] != null)
            newWidth = Convert.ToInt32(Request["w"].ToString());
        if (Request["h"] != null)
            newHeight = Convert.ToInt32(Request["h"].ToString());
        if (Request["mw"] != null)
            maxWidth = Convert.ToInt32(Request["mw"].ToString());
        if (Request["mh"] != null)
            maxHeight = Convert.ToInt32(Request["mh"].ToString());

        try
        {

            if (newWidth > 0 || newHeight > 0 || maxHeight > 0 || maxWidth > 0)
            {

                // resize and render the image

                // should cache it and reuse when possibl...

                Image i = Image.FromFile(Request.MapPath(Request.Path));

                using (MemoryStream ms = new MemoryStream())
                {

                    int newWidth2 = newWidth;
                    int newHeight2 = newHeight;

                    if (newWidth > 0 && newHeight == 0)
                        newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth);
                    else if (newHeight > 0 && newWidth == 0)
                        newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight);

                    if (newHeight2 == 0) newHeight2 = i.Height;
                    if (newWidth2 == 0) newWidth2 = i.Width;

                    if (maxWidth > 0 && newWidth2 > maxWidth)
                    {
                        newWidth2 = maxWidth;
                        newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth2);
                    }
                    if (maxHeight > 0 && newHeight2 > maxHeight)
                    {
                        newHeight2 = maxHeight;
                        newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight2);
                    }

                    Bitmap i2 = new Bitmap(i, newWidth2, newHeight2);

                    i2.Save(ms, GetImageFormatOfFile(file));

                    Response.BinaryWrite(ms.ToArray());
                }

            }
            else
            {
                // is there a way to call default handler instead of this??
                Response.WriteFile(Request.MapPath(Request.Path));
            }
        }
        catch
        {
            Response.WriteFile(Request.MapPath(Request.Path));
        }

        Response.End();
    }
开发者ID:ronmichael,项目名称:img2,代码行数:81,代码来源:ImgHandler.cs


注:本文中的HttpResponse.WriteFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。