当前位置: 首页>>代码示例>>C#>>正文


C# FilterEffect.GetBitmapAsync方法代码示例

本文整理汇总了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
                        }
                    };
                }
            }
        }
开发者ID:NathanAUS,项目名称:optical-reader,代码行数:29,代码来源:BasicEnhancer.cs

示例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);
                        })
                    };
                }
            }
        }
开发者ID:NathanAUS,项目名称:optical-reader,代码行数:55,代码来源:BasicNormalizer.cs


注:本文中的FilterEffect.GetBitmapAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。