首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部分灰度的ColorMatrix

部分灰度的ColorMatrix
EN

Stack Overflow用户
提问于 2012-06-10 04:01:21
回答 1查看 2.1K关注 0票数 1

所以我使用了一个我在网络上找到的东西的变体来将图像转换成灰度。我希望能够“淡入灰色”,即渐进式地淡出颜色,这样我就可以从全色到部分颜色再到纯灰色。

代码语言:javascript
复制
public static ColorMatrix ColorMatrixForGrayScale = new ColorMatrix(new[] {
                             new[] {.3f, .3f, .3f, 0, 0},
                             new[] {.59f, .59f, .59f, 0, 0},
                             new[] {.11f, .11f, .11f, 0, 0},
                             new float[] {0, 0, 0, 1, 0},
                             new float[] {0, 0, 0, 0, 1} });

    public static Bitmap MakeGrayscale(Image original, int percent = 100)
    {
        ColorMatrix matrix = GetMatrix(percent); // returns a variation of the above.

        //create a blank bitmap the same size as original
        var newBitmap = new Bitmap(original.Width, original.Height);

        //get a graphics object from the new image
        var g = System.Drawing.Graphics.FromImage(newBitmap);

        //create some image attributes
        var attributes = new ImageAttributes();

        //set the color matrix attribute
        attributes.SetColorMatrix(matrix);

        //draw the original image on the new image
        //using the grayscale color matrix
        g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
           0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

        //dispose the Graphics object
        g.Dispose();
        return newBitmap;
    }

所以问题有两个部分。首先,我可以使用矩阵吗?如果是,我有什么不同,如果不是,什么是可行的方法?我正在考虑创建全灰度,然后将其与彩色图像合并(一些方法)。

谢谢

编辑:原始源Switch on the code

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-10 16:22:44

为了改变饱和度,http://www.codeproject.com/Tips/78995/Image-colour-manipulation-with-ColorMatrix上有一篇有趣的文章

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10964179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档