0

I have a problem with my Images I uploaded as IFormFile in my .net5 API.

When I copy the IFormFile to MemoryStream and convert it to an iIage, the image is rotated whenever it is not landscape.

[HttpPost("Image/Upload")]
public async Task<IActionResult> upload(IFormFile myFile)
{
    var memoryStream = new MemoryStream();
    await myFile.CopyToAsync(memoryStream);
    memoryStream.Position = 0;
    var img = Image.FromStream(memoryStream);
    return Ok();
}

I upload an image with height: 3000px and width: 2000px. The results from img are height: 2000px and width 300px.

Can someone explain what is wrong here?

Thank you very much.

wohlstad
  • 12,661
  • 10
  • 26
  • 39
Turbo
  • 1
  • To be clear: does it work correctly with `Image.FromStream(myFile)`, or if you copy it to a file, say, instead of a `MemoryStream`? also: what is the thing being uploaded? is it *actually* rotated, or does it have a rotatated metadata flag that `Image.FromStream` isn't processing correctly? – Marc Gravell Mar 07 '22 at 10:23
  • 4
    This is probably due to `exif` orientation information that is stored in the image. The answers for this question might help you https://stackoverflow.com/questions/27835064/get-image-orientation-and-rotate-as-per-orientation – Martijn Lentink Mar 07 '22 at 10:25

0 Answers0