How to use ColorMatrix in .NET to change brightness, color, saturation, hue

I have a type “Bitmap” containing some random bitmap data. I wrote my own settings for brightness, color, saturation and hue, which act on each bit individually and, not surprisingly, it is terribly slow.

In my research, I noticed that using matrices can be very quick in adjusting them. In addition, .NET has ColorMatrix, where you can apply matrix effects when drawing DrawImage ().

The matrix we created is as follows (from the MSDN website):

float[][] colorMatrixElements = { 
new float[] {2,  0,  0,  0, 0},        // red scaling factor of 2
new float[] {0,  1,  0,  0, 0},        // green scaling factor of 1
new float[] {0,  0,  1,  0, 0},        // blue scaling factor of 1
new float[] {0,  0,  0,  1, 0},        // alpha scaling factor of 1
new float[] {.2f, .2f, .2f, 0, 1}};    // three translations of 0.2

But I could not find the correct ranges or what any of these numbers actually does. I don’t know how to adjust brightness, color, saturation and hue.

Any help ?? Am I missing some good documentation somewhere?

Thank!!

+3
source share
2 answers

There are a few details at http://www.graficaobscura.com/matrix/index.html , but you can send your other code. Performing operations on a pixel is very common, and you usually do not encounter performance problems for this kind of operation .. NET Bitmap.SetPixel is known to be slow. There is a good series of C # image processing in a code project showing a faster method. I have no experience with C ++ - cli, but I will take a look.

+4
source

There are restrictions on what you can do with the color matrix.

, , , 4- . , , , , (R G B A) .

. .

+1

Source: https://habr.com/ru/post/1789796/


All Articles