Resize and crop images using ImageResizer

I am trying to resize and then collect square images. I have an image in ReadOnlyStream and you want to output to a MemoryStream .

I am using ImageResizer for this.

I would like my images to first be reduced in size and then centered. I use this code, but it does not create what I need. He produces nothing ...

 var resultStream = new MemoryStream(); ImageJob job = new ImageJob(imageStream, resultStream, new Instructions { Width = 100, Height = 100, Mode = FitMode.Crop }); job.Build(); 

This code should reduce the size of large images and crop them based on the default values โ€‹โ€‹in the library (center crop).

I did not provide any specific configuration in web.config because, as far as I understand, this is not required.

What am I doing wrong?

+5
source share
1 answer

ImageResizer does not reset the position of the output stream to 0 after it is written, as this will break unused recording streams such as HttpResponseStream.

You need to call resultStream.Seek(0, SeekOrigin.Begin); before reading from it.

+8
source

Source: https://habr.com/ru/post/1206252/


All Articles