使用一般处理程序来提供图片

    public void ProcessRequest(HttpContext context)
    {
        //参数
        string imgcid=context.Request["imgcid"];
        string imgWidth = context.Request["imgWidth"];
        string strFilePath=TaiHeWenHuaHelper.GetCJImgPath(imgcid, Convert.ToInt32(imgWidth)); //获得图片的路径

        FileStream fs = new FileStream(context.Server.MapPath(strFilePath) , FileMode.Open);//获得图片的物理路径后把图片读取到文件流中
        byte[] bytes = new byte[(int)fs.Length];
        fs.Read(bytes, 0, bytes.Length);
        fs.Close();

        context.Response.ClearContent();
        context.Response.ContentType = "image/jpg"; //图片的格式
        context.Response.BinaryWrite(bytes);  //输出图片
    }

 

posted @ 2016-02-19 14:16  jamess  阅读(322)  评论(0编辑  收藏  举报