本文整理汇总了C#中FilterEffect.GetBitmapAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FilterEffect.GetBitmapAsync方法的具体用法?C# FilterEffect.GetBitmapAsync怎么用?C# FilterEffect.GetBitmapAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilterEffect
的用法示例。
在下文中一共展示了FilterEffect.GetBitmapAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnhanceAsync
public async Task<EnhanceResult> EnhanceAsync(Frame frame)
{
using (var bitmap = new Bitmap(new Windows.Foundation.Size(frame.Dimensions.Width, frame.Dimensions.Height), Internal.Utilities.FrameFormatToColorMode(frame.Format), frame.Pitch, frame.Buffer.AsBuffer()))
using (var source = new BitmapImageSource(bitmap))
using (var effect = new FilterEffect(source))
using (var renderer = new BitmapRenderer(effect))
{
effect.Filters = new List<IFilter>()
{
new ContrastFilter(0.5)
};
using (var newBitmap = new Bitmap(new Windows.Foundation.Size(frame.Dimensions.Width, frame.Dimensions.Height), Internal.Utilities.FrameFormatToColorMode(frame.Format)))
{
await effect.GetBitmapAsync(newBitmap, OutputOption.PreserveAspectRatio);
return new EnhanceResult()
{
Frame = new Frame()
{
Buffer = newBitmap.Buffers[0].Buffer.ToArray(),
Pitch = newBitmap.Buffers[0].Pitch,
Format = frame.Format,
Dimensions = newBitmap.Dimensions
}
};
}
}
}
示例2: NormalizeAsync
public async Task<NormalizeResult> NormalizeAsync(Frame frame, Windows.Foundation.Rect area, double rotation)
{
using (var bitmap = new Bitmap(frame.Dimensions, Internal.Utilities.FrameFormatToColorMode(frame.Format), frame.Pitch, frame.Buffer.AsBuffer()))
using (var source = new BitmapImageSource(bitmap))
using (var effect = new FilterEffect(source))
using (var renderer = new BitmapRenderer(effect))
{
effect.Filters = new List<IFilter>()
{
new ReframingFilter(area, -rotation)
};
using (var newBitmap = new Bitmap(new Windows.Foundation.Size(area.Width, area.Height), Internal.Utilities.FrameFormatToColorMode(frame.Format)))
{
await effect.GetBitmapAsync(newBitmap, OutputOption.PreserveAspectRatio);
return new NormalizeResult()
{
Frame = new Frame()
{
Buffer = newBitmap.Buffers[0].Buffer.ToArray(),
Pitch = newBitmap.Buffers[0].Pitch,
Format = frame.Format,
Dimensions = newBitmap.Dimensions
},
Translate = new Func<Windows.Foundation.Point, Windows.Foundation.Point>((normalizedPoint) =>
{
var rotationRadians = -rotation / 360.0 * 2.0 * Math.PI;
var sin = Math.Sin(rotationRadians);
var cos = Math.Cos(rotationRadians);
var origoX = area.Width / 2.0;
var origoY = area.Height / 2.0;
// Translate point to origo before rotation
var ox = normalizedPoint.X - origoX;
var oy = normalizedPoint.Y - origoY;
// Move area to origo, calculate new point positions, restore area location and add crop margins
var x = ox * cos - oy * sin;
var y = ox * sin + oy * cos;
// Translate point back to area after rotation
x = x + origoX;
y = y + origoY;
// Add margins from original uncropped frame
x = x + area.X;
y = y + area.Y;
return new Windows.Foundation.Point(x, y);
})
};
}
}
}