سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top