【问题标题】:Instagram Photo Effects in Windows 8 metro apps using c#使用 c# 在 Windows 8 Metro 应用程序中的 Instagram 照片效果
【发布时间】:2026-01-27 17:15:02
【问题描述】:
【问题讨论】:
标签:
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;
}
如果您遇到任何问题,请告诉我。