HttpResponse输出图像


    /// 
    /// 输出图像
    /// 
    /// 
    /// 
    /// 
    private void OutPutPic(Bitmap pic, string filename, HttpResponse Response)
    {
        System.IO.MemoryStream stream = new System.IO.MemoryStream(); // 创建支持存储区的内存流
        pic.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);    // 保存图片

        Response.ClearContent();                // 清空缓冲区
        Response.ContentType = "Image/jpeg";    // 以图像形式输出

        if (!filename.EndsWith(".jpg")) filename += ".jpg";
        Response.AddHeader("Content-Disposition", "filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));    // 设置输出时的文件名
                                                                                                                                //Response.AddHeader("Content-Disposition", (isDownload ? "attachment; " : "") + "filename=" + HttpUtility.UrlEncode(reName, System.Text.Encoding.UTF8));   // 下载
        Response.BinaryWrite(stream.ToArray()); // 将流内容输出至Response接收端
    }

你可能感兴趣的:(C#,Response输出图像)