ImageSharp icon indicating copy to clipboard operation
ImageSharp copied to clipboard

Blur image after resizing and conversion to base64 string

Open z-tc opened this issue 8 years ago • 4 comments

Description

I am converting resized image to byte array and then to base64 so i could show it on frontend side.

Steps to reproduce

Resizing: sourceImage.Mutate(x => x.Resize(width, height));

I also tried with: sourceImage.Mutate(x => x.Resize(new ResizeOptions { Size = new Size(width, height), Mode = ResizeMode.Max })); but still the same, i can not get sharp image.

Conversion to base64: using (var outputStream = new MemoryStream()) { image.Save(outputStream, new JpegDecoder()); var bytes = outputStream.ToArray(); return Convert.ToBase64String(bytes); }

Am I missing something?

Thanks

System Configuration

  • Environment (Operating system, version and so on): Windows 10
  • .NET Framework version: .NET Core 2.0
  • Additional information:

z-tc avatar Apr 30 '18 07:04 z-tc

Have you compared the output of the encoder saving to a file to the redecoded output from your image viewer? Encoding the byte array to a string simply encoded the bytes, the method is lossless.

JimBobSquarePants avatar Apr 30 '18 07:04 JimBobSquarePants

@z-tc Hello?

JimBobSquarePants avatar May 07 '18 06:05 JimBobSquarePants

sorry for delay, seems that my css on web client managed to break image aspect ratio. for some reason base64 image fits in all my divs correctly without resizing, so when i do the resize, resized image stretch to fill the div and i get blur image. so, library is doing the job well on the end. thanks for quick answer

z-tc avatar May 07 '18 10:05 z-tc

Ah awesome, good to know, thanks! 😄

JimBobSquarePants avatar May 07 '18 10:05 JimBobSquarePants