示例#1
0
        public static async Task <BitmapSource> GetScreenShot(this MediaElement source, int zoom)
        {
            var result = (await source.CaptureBitmapAsync()).CreateBitmapSourceFromBitmap();

            var renderHeight = (double)source.NaturalVideoHeight;
            var renderWidth  = (double)source.NaturalVideoWidth;

            var zoomedBitmap  = new TransformedBitmap(result, new ScaleTransform(zoom, zoom));
            var croppedBitmap = new CroppedBitmap(zoomedBitmap, new Int32Rect(
                                                      (int)(zoomedBitmap.Width / 2 - renderWidth / 2),
                                                      (int)(zoomedBitmap.Height / 2 - renderHeight / 2),
                                                      (int)renderWidth,
                                                      (int)renderHeight
                                                      ));

            return(croppedBitmap);
        }