Domanda

I'm trying to convert image from colored into grayscale but the grayscale level is depended on the slider level. Most of the tutorial I found in internet is making it into absolute grayscale. Thanks for your answers, I very appreciate it

È stato utile?

Soluzione

You should use some interpolation between full-color image and grayscale version with coefficient determined by the slider's value. For example, if you convert to grayscale using ColorMatrix, as described here, then, to get partially grayed image, you should apply interpolated matrix. Say, "slider=0" is full-color and "slider=1" is grayscale, then the matrix to apply is defined:

<color_matrix_to_apply> = slider * <grayscale_matrix> + (1 - slider) * <identity_matrix>

As ColorMatrix does not provide ariphmetic operations, you should implement this formula "manually", for each item of the matrices.

matrixToApply.Matrix00 = slider * grayscaleMatrix.Matrix00 + (1 - slider) * identityMatrix.Matrix00;
...
matrixToApply.Matrix44 = slider * grayscaleMatrix.Matrix44 + (1 - slider) * identityMatrix.Matrix44;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top