I have updated my project from .NET 4.5 to .NET Core (with ASP.NET Core). I had some very simple code in my previous version that used the bitmap object from System.Drawing
to resize an image.
As I understand System.Drawing
cannot be used in .NET Core because it is not cross platform, but what can be used instead?
I have googled this and cannot find anything. The only thing I can find is this post, which has no code on it what so ever.
Resizing an Image can be done in a range of ways. The easiest method is to create a new Bitmap object from the in-memory image. When creating the Bitmap object, you assign the new dimension in the Size parameter. Finally, the resized Bitmap is written to a byte array.
To upload the image, click on Choose File and then browse to the image which you want to upload. Once the image is selected then the name of the image will be displayed next to the Choose File button as shown in the following screenshot. As you can see the that images.
Place the images in a new folder named images in the app's web root ( wwwroot ). The use of the images folder is only for demonstration purposes. You can organize images in any folder layout that you prefer, including serving the images directly from the wwwroot folder.
Disclaimer: This is my software.
I'm working on a cross-platform 2D Graphics library that runs on .NET Core It's currently alpha but already supports a comprehensive feature set.
https://github.com/JimBobSquarePants/ImageSharp
Example usage.
using (FileStream stream = File.OpenRead("foo.jpg")) using (FileStream output = File.OpenWrite("bar.jpg")) { Image image = new Image(stream); image.Resize(image.Width / 2, image.Height / 2) .Greyscale() .Save(output); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With