【问题标题】:How to convert submitted image to stream?如何将提交的图像转换为流?
【发布时间】:2014-03-25 08:46:42
【问题描述】:

我发布了一张带有图片的表格。 并在我的控制器中接收它

var image=Request.Files["hiddenUploadButton"];

现在我想将我的图像转换为 Stream。该怎么做?

【问题讨论】:

    标签: asp.net image


    【解决方案1】:
    var stream  = Request.Files["hiddenUploadButton"].InputStream;
    

    请参阅this link

    也许你想做this之类的事情?

    【讨论】:

      【解决方案2】:
       if you want to save file try following code snippet
      
       HttpPostedFile file = Request.Files["myFile"];
      
          //check file was submitted
          if (file != null && file.ContentLength > 0)
          {
              string fname = Path.GetFileName(file.FileName);
              file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
          }
      

      如何转换为流,

           HttpPostedFile file = Request.Files["myFile"];
      var FileLen = file .ContentLength;
         byte[] input = new byte[FileLen];
        System.IO.Stream MyStream;
         // Initialize the stream.
         MyStream = file .InputStream;
      
         // Read the file into the byte array.
         MyStream.Read(input, 0, FileLen);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-24
        • 2015-02-11
        • 2015-10-17
        • 2014-06-07
        • 1970-01-01
        相关资源
        最近更新 更多