Need to calculate the Value of a pixel [closed]
I have a RGBA values, R - 255, G - 103, B - 103, Alpha - 103.
Need combination of the (RGB) color value. Example - 26532.(combination of colour value/Pixel value)
Description - Image is made of pixels, each pixel has combination of colors(like - RGB). Need to calculate the mean of the image and we need to have the unique value of the pixel. Each pixel has 4 colour values but need the pixel value( combination of colo开发者_Python百科ur values)
You can use BitConverter
to convert the RGBA bytes to a single int
value:
byte[] components = new byte[4];
components[0] = 103; // blue
components[1] = 103; // green
components[2] = 255; // red
components[3] = 103; // alpha
int pixelValue = BitConverter.ToInt32(components, 0);
You should be able to do a loop through every pixel, and calculate the pixel value on the fly if you know the pixel color values.
Relevant questions:
How can I iterate through each pixel in a .gif image in C#?
How to calculate the average rgb color values of a bitmap
int value = Color.FromArgb(103, 103, 255, 103).ToArgb()
精彩评论