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:
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?
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));
...
}