Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save stream as image

Tags:

c#

asp.net

How to save stream as image and store the image in temp files?

like image 480
banupriya Avatar asked Sep 06 '10 11:09

banupriya


People also ask

How do I upload pictures from stream?

To load an image from stream, instantiate the FileStream class to read the image in the stream and load the file in GcBitmap object using the Load method with FileStream object as its parameter.

How do I save an image in C sharp?

Image bitmap = Image. FromFile("C:\\MyFile. bmp"); bitmap. Save("C:\\MyFile2.

How do I save a bitmap image in C#?

you can choose different available formats Tiff, Jpeg, PNG, BMP, etc.., depending on your selection you can select the format which you want to encode and save. And you can set this saved file path as Image source like the following: // Get a photo as a Bitmap Image using storage file path.


2 Answers

Try

Image img = System.Drawing.Image.FromStream(myStream);

img.Save(System.IO.Path.GetTempPath() + "\\myImage.Jpeg", ImageFormat.Jpeg);
like image 164
Unmesh Kondolikar Avatar answered Oct 09 '22 10:10

Unmesh Kondolikar


var tempFile = Path.GetTempFileName();
using (var fs = File.Create(tempFile))
{
   source.copyTo(fs);
}

where source is source stream. Now your source stream is saved at temp location (given by tempFile). Note that file name extension will be TMP.

like image 43
VinayC Avatar answered Oct 09 '22 10:10

VinayC