Manipulating images with .NET Core

微笑、不失礼 提交于 2019-11-26 10:57:18

问题


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.


回答1:


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);
}



回答2:


You can use now official (from Microsoft) System.Drawing.Common NuGet package.




回答3:


I've found an implementation of System.Drawing for .NET Core based on Mono's sources being maintained at:

  • https://github.com/CoreCompat/CoreCompat

The NuGet package is at:

  • https://www.nuget.org/packages/CoreCompat.System.Drawing

Which you can reference it in your .NET Core App's project.json with:

{
  "dependencies": {
    "CoreCompat.System.Drawing": "1.0.0-beta006",
    ...
  },
}


来源:https://stackoverflow.com/questions/33344200/manipulating-images-with-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!