3

I have a code like this:

 using (var image = Image.FromFile(imagePath))
                {
                    image.Save(Path.ChangeExtension(imagePath, "jpg"), ImageFormat.Jpeg);                        
                }

This converts the given image file into different format and saves it onto the HDD.

How can I convert the image into JPG, but instead of saving it, I want to put it into a byte[] variable. Something like:

byte[] img = image.ByteArray(Path.ChangeExtension(imagePath, "jpg"), ImageFormat.Jpeg);  

Is this possible to do, without saving the image onto the HDD first and then loading it into byte array from a file?

Askerman
  • 787
  • 1
  • 12
  • 31
  • Actually it is not a duplicate bcs in the other question answer there was a System.Drawing assembly based method while in .NET Core there is no equivalent functionality. Therefore code from question and linked answer simply will fail with exception. – Jacek Blaszczynski Nov 19 '17 at 20:35

0 Answers0