public void RecoverAfterDeviceLost() { if (regionMask != null) { regionMask.Dispose(); } if (currentRegionMask != null) { regionMask = new CanvasRenderTarget(SourceBitmap.Device, Parent.Size.X, Parent.Size.Y, 96); regionMask.SetPixelBytes(currentRegionMask); } cachedRegionMask.RecoverAfterDeviceLost(); }
void canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args) { switch (args.Reason) { case CanvasCreateResourcesReason.FirstTime: // First time initialization: either restore suspended app state, load a // photo that was passed in from the shell, or bring up the file selector. if (launchArg is ApplicationExecutionState && (ApplicationExecutionState)launchArg == ApplicationExecutionState.Terminated) { var restoreTask = RestoreSuspendedState(sender.Device); args.TrackAsyncAction(restoreTask.AsAsyncAction()); } else { if (!TryLoadPhoto(launchArg as IReadOnlyList <IStorageItem>)) { LoadButton_Click(null, null); } } break; case CanvasCreateResourcesReason.NewDevice: // Recovering after a lost device (GPU reset). if (photo.SourceBitmap != null) { photo.RecoverAfterDeviceLost(sender.Device); } cachedImage.RecoverAfterDeviceLost(); break; case CanvasCreateResourcesReason.DpiChanged: // We mostly work in pixels rather than DIPs, so only need // minimal layout updates in response to DPI changes. if (photo.SourceBitmap != null) { ZoomToFitPhoto(); } break; } }