【问题标题】:Instagram Photo Effects in Windows 8 metro apps using c#使用 c# 在 Windows 8 Metro 应用程序中的 Instagram 照片效果
【发布时间】:2026-01-27 17:15:02
【问题描述】:

我需要实现 Instagram 照片效果,例如 amaro、hudson、sepia、rise 等。我知道这篇文章只使用基本效果:http://code.msdn.microsoft.com/windowsdesktop/Metro-Style-lightweight-24589f50

人们建议的另一种方法是实现 Direct2d,然后使用它进行应用。但为此我需要编写 C++ 代码,而我的经验为零。

任何人都可以建议一些其他方法来在 c# 中实现 Instagram 效果吗?

这些效果是否有任何内置的 c++ 文件?

【问题讨论】:

    标签: c# image-processing colors microsoft-metro direct2d


    【解决方案1】:

    请参阅 CodeProject 中的此示例:Metro Style Lightweight Image Processing

    以上示例包含这些图像效果。

    • 否定
    • 彩色滤光片
    • 浮雕
    • 阳光
    • 黑白
    • 亮度
    • 油画
    • 色调

    请注意,上面的例子似乎是在 Windows 8 的开发者预览版或发布预览版上实现的。所以你会得到这样的错误

    'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' 不包含 带 1 个参数的构造函数

    所以你必须通过传递图像的像素高度和像素宽度来创建WriteableBitmap 的实例。我已经编辑了示例,它对我有用。您必须将wb = new WriteableBitmap(bs); 更改为wb = await GetWB();

    StorageFile originalImageFile;
    WriteableBitmap cropBmp;
    public async Task<WriteableBitmap> GetWB()
    {
        if (originalImageFile != null)
        {
            //originalImageFile is the image either loaded from file or captured image.
            using (IRandomAccessStream stream = await originalImageFile.OpenReadAsync())
            {
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(stream);
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
                byte[] pixels = await GetPixelData(decoder, Convert.ToUInt32(bmp.PixelWidth), Convert.ToUInt32(bmp.PixelHeight));
                cropBmp = new WriteableBitmap(bmp.PixelWidth, bmp.PixelHeight);
                Stream pixStream = cropBmp.PixelBuffer.AsStream();
                pixStream.Write(pixels, 0, (int)(bmp.PixelWidth * bmp.PixelHeight * 4));
            } 
        }
        return cropBmp;
    }
    

    如果您遇到任何问题,请告诉我。

    【讨论】:

      最近更新 更多