How to save stream as image and store the image in temp files?
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.
Image bitmap = Image. FromFile("C:\\MyFile. bmp"); bitmap. Save("C:\\MyFile2.
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.
Try
Image img = System.Drawing.Image.FromStream(myStream);
img.Save(System.IO.Path.GetTempPath() + "\\myImage.Jpeg", ImageFormat.Jpeg);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With