简体   繁体   中英

c# - wp - convert image to grayscale according to slider value

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM