0

I'm trying to resize images into thumbnails in a .NET Core C# application using SixLabors.ImageSharp (version 1.0.0-beta0007). I've noticed that for only certain images, the resized image has a white, red, or blue distorted border, like so:

enter image description here

enter image description here

My code for generating the thumbnail is as follows:

        using (var imageToResize = Image.Load(inStream, out IImageFormat imageFormat))
        {
            var size = GetThumbnailSize(imageToResize.Size()); //max size 150,preserves aspect-ratio 
            imageToResize.Mutate(x => x.Resize(new ResizeOptions()
            {
                Size = size,
                Mode = ResizeMode.Crop
            }));

            using (var memorystream = new MemoryStream())
            {
                imageToResize.Save(memorystream , imageFormat);
                ms.Position = 0;
                outputStream.UploadFromStreamAsync(memorystream);
            }
        }

These two images were captured from the same device, and both have the same dimension (3024x4032) and these are the only similarities I could notice as I am a novice to image processing. I've also played around with the resize modes and different Resamplers, but could not resolve this.

What is causing this issue? Is there any way to fix this by using the SixLabors.ImageSharp library?

noobmaster007
  • 153
  • 2
  • 11
  • 1
    Likely a problem with your input stream not providing all the bytes. I'm guessing you're using Azure by the `UploadFromStreamAsync`method call. Copy your input stream to a `MemoryStream` and try loading from there. – James South May 01 '20 at 12:44
  • Thank you @JamesSouth ! I got it done by mapping the input stream to a byte array and loading the Image from that. – noobmaster007 May 23 '20 at 16:52

1 Answers1

0

The issue was resolved after I modified the code to load the ImageSharp Image from a byte array instead of a stream. As per @JamesSouth's comment on the question above, it might have been my input stream not providing the all the bytes.

Below is the updated code:

   // convert inStream to a byte array "bytes"

    using (var imageToResize = Image.Load(bytes, out IImageFormat imageFormat))
    {
        Size newSize = GetThumbnailSize(imageToResize.Size()); //max size 150, preserves aspect-ratio 
        imageToResize.Mutate(x => x.Resize(newSize));

        ...
    }
noobmaster007
  • 153
  • 2
  • 11