0

单击按钮后,如何将照片处理为棕褐色。

下面是我的代码:

private void button1_Click(object sender, RoutedEventArgs e)
{
    BitmapSource image = (BitmapSource)video.Source;
    image.Save(DateTime.Now.ToString("ddMMyyyy HHmmss") + ".jpg", ImageFormat.Jpeg);
    MessageBox.Show("Saved on bin/debug");
}
4

1 回答 1

0

您可以像这里WriteableBitmap一样使用和操作它的像素数据。unsafe

然后你可以使用

    public static void ToSepia(this WriteableBitmap wrb)
    {
        // ForEach...
        // (...ForEach(this WriteableBitmap bmp, Func<int, int, Color, Color> func)...)
        //
        wrb.ForEach((x, y, c) =>
        {
            // Convert color to grayscale.
            byte grayScale = (byte)((c.R * .3) + (c.G * .59) + (c.B * .11));
            // Init new color with taking same alpha.
            Color newColor = Color.FromArgb(c.A, grayScale, grayScale, grayScale);
            // Apply sepia and return new color.
            return new Color()
            {
                R = (byte)(newColor.R * 1),
                G = (byte)(newColor.G * 0.95),
                B = (byte)(newColor.B * 0.82),
            };
        });
    }

这是 SL 的帮助程序库,但最近还制作了 wpf 版本(在源代码管理中检查分支)。http://writeablebitmapex.codeplex.com/

于 2012-02-10T15:26:40.797 回答