ImageSharp. NET Core cross-platform graphics processing library, imagesharpcore

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.