Example #1
0
 /// <summary>
 /// Handles the DisplayContentsInvalidated event
 /// </summary>
 /// <param name="sender">DisplayInformation</param>
 /// <param name="args">Event arguments</param>
 private void OnDisplayContentsInvalidated(DisplayInformation sender, object args)
 {
     //
     // This will trigger the device lost event
     //
     _canvasDevice.RaiseDeviceLost();
 }
Example #2
0
 void CoreApplication_Suspending(object sender, SuspendingEventArgs args)
 {
     try
     {
         device.Trim();
     }
     catch (Exception e) when(device.IsDeviceLost(e.HResult))
     {
         device.RaiseDeviceLost();
     }
 }
Example #3
0
        public async Task <CanvasImageSource> RenderToImageSourceAsync(
            RenderTargetBitmap backgroundBitmap,
            IReadOnlyList <InkStroke> inkStrokes, IReadOnlyList <InkStroke> highlightStrokes, double width, double height)
        {
            var dpi         = DisplayInformation.GetForCurrentView().LogicalDpi;
            var imageSource = new CanvasImageSource(_canvasDevice, (float)width, (float)height, dpi);


            using (var drawingSession = imageSource.CreateDrawingSession(Colors.White))
            {
                try
                {
                    var pixels = await backgroundBitmap.GetPixelsAsync();

                    var bitmap = SoftwareBitmap.CreateCopyFromBuffer(pixels, BitmapPixelFormat.Bgra8,
                                                                     backgroundBitmap.PixelWidth, backgroundBitmap.PixelHeight);
                    var convertedImage = SoftwareBitmap.Convert(
                        bitmap,
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Premultiplied
                        );
                    var background = CanvasBitmap.CreateFromSoftwareBitmap(_canvasDevice, convertedImage);
                    drawingSession.DrawImage(background, new Rect(0, 0,
                                                                  width,
                                                                  height));
                    drawingSession.DrawInk(inkStrokes);

                    return(imageSource);
                }
                catch (Exception e) when(_canvasDevice.IsDeviceLost(e.HResult))
                {
                    _canvasDevice.RaiseDeviceLost();
                }

                return(null);
            }
        }
Example #4
0
 private void ResetDevices(bool IsDeviceLost)
 {
     try
     {
         if (IsDeviceLost)
         {
             _canvasDevice.DeviceLost -= _canvasDevice_DeviceLost;
             _canvasDevice             = CanvasDevice.GetSharedDevice();
             _canvasDevice.DeviceLost += _canvasDevice_DeviceLost;
         }
         CanvasComposition.SetCanvasDevice(_graphicsDevice, _canvasDevice);
     }
     catch (Exception e) when(_canvasDevice != null && _canvasDevice.IsDeviceLost(e.HResult))
     {
         _canvasDevice.RaiseDeviceLost();
     }
 }
Example #5
0
        public async Task <SoftwareBitmap> RenderAsync(IEnumerable <InkStroke> inkStrokes, double width, double height)
        {
            var dpi = DisplayInformation.GetForCurrentView().LogicalDpi;

            try
            {
                var renderTarget = new CanvasRenderTarget(_canvasDevice, (float)width, (float)height, dpi);
                using (renderTarget)
                {
                    using (var drawingSession = renderTarget.CreateDrawingSession())
                    {
                        drawingSession.DrawInk(inkStrokes);
                    }

                    return(await SoftwareBitmap.CreateCopyFromSurfaceAsync(renderTarget));
                }
            }
            catch (Exception e) when(_canvasDevice.IsDeviceLost(e.HResult))
            {
                _canvasDevice.RaiseDeviceLost();
            }

            return(null);
        }
Example #6
0
 private void DeviceRemoved(DeviceLostHelper sender, object args)
 {
     _canvasDevice.RaiseDeviceLost();
 }
Example #7
0
 private void _deviceLostHelper_DeviceLost(object sender, DeviceLostEventArgs e)
 {
     _canvasDevice.RaiseDeviceLost();
 }