Convert Byte Array Tiff To Byte Array Jpeg
-
02-07-2021 - |
Question
How can I convert a byte array from tiff image to a byte array of jpg?
I have the byte array of Tiff image from the web, then how can i use it as jpg without writing a new file?
Solution
Byte[] tiffBytes;
Byte[] jpegBytes;
using (MemoryStream inStream = new MemoryStream(tiffBytes))
using (MemoryStream outStream = new MemoryStream())
{
System.Drawing.Bitmap.FromStream(inStream).Save(outStream, System.Drawing.Imaging.ImageFormat.Jpeg);
jpegBytes = outStream.ToArray();
}
I didn't try it but it should work. If you are going to save the file last you can just use the save method on the bitmap with a file path instead of a stream.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow