.ashx接收APPCAN发送过来的图片数据流,保存为图片

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.IO;  
  6. using System.Drawing;  
  7. using System.Web.SessionState;  
  8. namespace BlankOrder  
  9. {  
  10.     /// <summary>  
  11.     /// ImageHandler 的摘要说明  
  12.     /// </summary>  
  13.     public class ImageHandler : IHttpHandler, IReadOnlySessionState  
  14.     {  
  15.   
  16.         public void ProcessRequest(HttpContext context)  
  17.         {  
  18.               
  19.             var httpRequest = System.Web.HttpContext.Current.Request;  
  20.             HttpFileCollection uploadFiles = httpRequest.Files;  
  21.             try  
  22.             {  
  23.   
  24.                 //int vals = context.Request.TotalBytes;  
  25.                 //byte[] buffer = context.Request.BinaryRead(vals);  
  26.                 string imgname = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";  
  27.                 string filePath = "/img/userupphoto/" + imgname;  
  28.                 if (context.Request.Files.Count > 0)  
  29.                 {  
  30.               
  31.                     int i;  
  32.                     for (i = 0; i < uploadFiles.Count; i++)  
  33.                     {  
  34.                         HttpPostedFile postedFile = uploadFiles[i];  
  35.                         Image img = new Bitmap(postedFile.InputStream);  
  36.                         img.Save(context.Server.MapPath(filePath));  
  37.                         img.Dispose();  
  38.                     }  
  39.                 }  
  40.                
  41.   
  42.             }  
  43.             catch (Exception e)  
  44.             {  
  45.                  
  46.             }  
  47.              
  48.         }  
  49.   
  50.         public bool IsReusable  
  51.         {  
  52.             get  
  53.             {  
  54.                 return false;  
  55.             }  
  56.         }  
  57.     }  
  58. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值