联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> Algorithm 算法作业Algorithm 算法作业

日期:2020-01-06 09:49

Working with images

Image class

An Image class contained in Image.cs has been provided on Blackboard. It is highly

recommended that you download and use this class in your project, as it encapsulates a lot of

convenient functionality for working with images. The Image class requires the

SixLabors.ImageSharp 3rd party library to be installed in your project.

Start by adding the Image.cs file into a new Console project (.NET core). You should familiarise

yourself with this class and the public members it exposes, because you will likely use them in

your solution!

Working with RGBA values and pixel intensities

RGBA values: RGBA stands for red, green, blue, alpha. Every pixel in our images has a RGBA

value. The alpha channel represents the the transparency of pixels (an alpha value of 0 indicates

complete transparency, and an alpha value of 255 indicates no transparency). In this assignment,

RGBA values are stored using the Rgba32 type. Each component is represented by a byte (an 8-

bit integer ranging from 0 to 255). For more information on the Rgba type, see the official

SixLabors documentation page. In our Image class, Rgba32 values at specific pixels can be

retrieved using square-bracket indexing (e.g. image[x, y].R ). The overall intensity of an RGBA

pixel can be retrieved using the image.GetGreyIntensity(...) method, which provides the average

intensity of the RGB channels (equivalent to the pixel values after converting to greyscale - hence

the method name GetGreyIntensity ).

Greyscale images: Greyscale images still have RGBA channels, but the values in the RGB

channels are identical. For example, the colour new Rgba32(25, 25, 25, 255) and new Rgba32(80,

80, 80, 255) each represent shades of grey. The colour new Rgba32(0, 0, 0, 255) represents

black, and the colour new Rgba32(255, 255, 255, 255) represents white. To convert an image to

greyscale, use Image.ToGreyscale(...) .

Examples

using SixLabors.ImageSharp.PixelFormats;  necessary for creating Rgba32 objects

...

 load an image

Image image1 = new Image("cat.png");

 create an image by copying an old one

Image image2 = new Image(image1);

 create a black image with a specific width and height

Image image3 = new Image(width: 400, height: 300);

 get the Rgba32 color of the pixel at x=25, y=30

Rgba32 color1 = image1[25, 30];

 get the overall pixel intensity at x=25, y=30

int intensity = image1.GetGreyIntensity(25, 30);

 create a color with the values r=50, g=80, b=55, and a=255

Rgba32 color2 = new Rgba32(50, 80, 55, 255);

 create a color that is 5% brighter than another color

Rgba32 color3 = new Rgba32(

(byte)(color1.R * 1.05),

(byte)(color2.G * 1.05),

(byte)(color2.B * 1.05),

(byte)(255)

);

 set a pixel to a new Rgba32 value

image1[25, 30] = color3;


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp