ImageSharp. NET Core cross-platform graphics processing library, imagesharpcore
ImageSharp supports. NET Core cross-platform graphics processing libraries, and ImageSharp is the. NET Core cross-platform implementation of ImageProcessor.
ImageSharp supports the following operations:
Resize, crop, flip, rotate, and edge detection.
Supports BMP, PNG, GIF, and JPEG encoder.
EXIF reads and writes to JPEG.
Currently, Drawing is not supported, that is, verification codes and watermarks cannot be supported.
GitHub: https://github.com/JimBobSquarePants/ImageSharp
The current version is 1.0.0-alpha7.
Create a project
Create a. NET Core console application.
Add reference
Because it is still alpha version, it has not been placed in NuGet yet. It is in MyGet https://www.myget.org/gallery/imagesharp.
Add the ImageSharp source to the NuGet package source.
ImageSharp Source Address: https://www.myget.org/F/imagesharp
Then run the following command on the NuGet console:
Install-Package ImageSharp -Version 1.0.0-alpha7
Write code
First, you need a picture and place it in the program root directory as lena.jpg.
The sample code is as follows:
Public static void Main (string [] args) {// read EXIF using (FileStream input = File. openRead ("lena.jpg") {Image image = new Image (input); var exif = image. exifProfile. values; foreach (var item in exif) {Console. writeLine (item. tag + ":" + item. value) ;}} // scale using (FileStream input = File. openRead ("lena.jpg") using (FileStream output = File. openWrite ("lena2.jpg") {Image image = new Image (input); image. resize (image. width/2, image. height/2 ). save (output);} // crop using (FileStream input = File. openRead ("lena.jpg") using (FileStream output = File. openWrite ("lena3.jpg") {Image image = new Image (input); image. crop (image. width/2, image. height/2 ). save (output);} // rotate 180 ° using (FileStream input = File. openRead ("lena.jpg") using (FileStream output = File. openWrite ("lena4.jpg") {Image image = new Image (input); image. rotate (RotateType. rotate180 ). save (output);} // you can set the pixel to empty using (FileStream output = File. openWrite ("lena5.jpg") {Image image = new Image (100,200); Color [] colors = new Color [20000]; for (int I = 0; I <20000; I ++) {colors [I] = Color. white;} image. setPixels (100,200, colors); image. save (output);} Console. readKey ();}
The following figure is displayed in the root directory of the program.
The above is the simple use of ImageSharp. For more information, see the official GitHub.
If you think this article is helpful to you, click"Recommendation", Thank you.