Example #1
0
        internal async void CaptureScreenshot(bool deckOnly)
        {
            var selectedDeck = DeckPickerList.SelectedDecks.FirstOrDefault();

            if (selectedDeck == null)
            {
                return;
            }
            Log.Info("Creating screenshot of " + selectedDeck.GetSelectedDeckVersion().GetDeckInfo());

            var deck   = selectedDeck.GetSelectedDeckVersion();
            var cards  = 35 * deck.Cards.Count;
            var height = (deckOnly ? 0 : 124) + cards;
            var width  = 219;

            DeckView control = new DeckView(deck, deckOnly);

            control.Measure(new Size(width, height));
            control.Arrange(new Rect(new Size(width, height)));
            control.UpdateLayout();
            Log.Debug($"Screenshot: {control.ActualWidth} x {control.ActualHeight}");

            RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(control);
            var encoder = new PngBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bmp));

            await SaveOrUploadScreenshot(encoder, deck.Name);
        }
        public static RenderTargetBitmap Generate(Deck deck, bool cardsOnly)
        {
            var height = CardHeight * deck.GetSelectedDeckVersion().Cards.Count;

            if (!cardsOnly)
            {
                height += InfoHeight;
            }
            var control = new DeckView(deck, cardsOnly);

            control.Measure(new Size(ScreenshotWidth, height));
            control.Arrange(new Rect(new Size(ScreenshotWidth, height)));
            control.UpdateLayout();
            Log.Debug($"Screenshot: {control.ActualWidth} x {control.ActualHeight}");
            var bmp = new RenderTargetBitmap(ScreenshotWidth, height, Dpi, Dpi, PixelFormats.Pbgra32);

            bmp.Render(control);
            return(bmp);
        }