1 //HttpPost 2 HttpRequest request = HttpContext.Current.Request; 3 HttpFileCollection filelist = request.Files; 4 HttpPostedFile file = filelist[0]; 5 file.SaveAs(filename); 6 7 //转Bitmap 8 //1、byte[] 9 MemoryStream ms = new MemoryStream(bytes); 10 Bitmap bmp = new Bitmap(ms); 11 //2、filename 12 Bitmap bmp= new Bitmap(filename); 13 //3、url(使用Flurl) 14 Stream stream = await url.GetStreamAsync(); 15 Bitmap bmp = new Bitmap(stream); 16 17 //输出 18 //1、文件 19 bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg); 20 //2、byte[] 21 MemoryStream ms = new MemoryStream(); 22 bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 23 byte[] image = ms.ToArray()
//byte[]转Stream Stream stream = new MemoryStream(bytes); //Stream转byte[] byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); stream.Seek(0, SeekOrigin.Begin); //设置当前流的位置为流的开始 //文件转byte[] FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); byte[] bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, bytes.Length); fileStream.Close(); //byte[]写入文件 FileStream fs = new FileStream(fileName, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(bytes); bw.Close(); fs.Close();
标签:文件,MemoryStream,stream,c#,bytes,保存,Bitmap,new,byte From: https://www.cnblogs.com/desertion/p/18574113