Manipulating Images with .Net Core

Simple image operations for .NET Core 6 and beyond

It depends on which platform you are building your app, but SkiaSharp 2.80.2 or 2.80.3 can be a good choice. There are quite a bit problems in newer packages, so you need to be careful which version you install so that you do not run into performance problems or bugs.

How to create thumbnail image in .net core? Using the help of IFormFile

Finally got the answer

Installed System.Drawing.Common -Version 4.5.1 package

Open the package manager and run the below code for installing the package

Install-Package System.Drawing.Common -Version 5.0.2

Then use the below code:

using System.Drawing;

var stream = ProductImage.OpenReadStream();

var newImage = GetReducedImage(32,32,stream);
newImage.Save("path+filename");

public Image GetReducedImage(int width, int height, Stream resourceImage)
{
try
{
var image = Image.FromStream(resourceImage);
var thumb = image.GetThumbnailImage(width, height, () => false, IntPtr.Zero);

return thumb;
}
catch (Exception e)
{
return null;
}
}


Related Topics



Leave a reply



Submit