| |

VerySource

 Forgot password?
 Register
Search
View: 637|Reply: 0

How to save a picture in a stream and then write it to a file.

[Copy link]

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-7 02:50:01
| Show all posts |Read mode
If a bitmap has been drawn

Stream s = new MemoryStream ();
bitmap.Save (s, ImageFormat.Jpeg);

using (FileStream fs = new FileStream (Server.MapPath ("aaaaaaa.jpg"), FileMode.Create))
{
  byte [] b = new byte [1024];
  int read = 0;
  while ((read = s.Read (b, 0, b.Length))> 0)
  {
    fs.Write (b, 0, read);
  }
}

The file can be generated, but the size is 0 K, there is no image, what's going on?
With bitmap.Save (Response.OutputStream, ImageFormat.Jpeg); you can see the picture.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list