From 1484a7d1889b59cc692fd0a84659cb81ef8826ef Mon Sep 17 00:00:00 2001 From: Vitalii Orazov Date: Mon, 17 Jul 2023 22:54:29 +0300 Subject: [PATCH] wip. ControlCatalog. handling of basic bitmap formats on the clipboard --- .../Pages/ClipboardPage.xaml.cs | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs b/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs index c96318507b..af413e383d 100644 --- a/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs @@ -131,14 +131,40 @@ namespace ControlCatalog.Pages { if (TopLevel.GetTopLevel(this)?.Clipboard is { } clipboard) { - var bytes = await clipboard.GetDataAsync("Bitmap") as IEnumerable - ?? await clipboard.GetDataAsync("Dib") as IEnumerable; + var format = "Bitmap"; + + var obj = await clipboard.GetDataAsync(format); + var bytes = obj as IEnumerable; + if (bytes == null) + { + format = "Dib"; + obj = await clipboard.GetDataAsync(format); + bytes = obj as IEnumerable; + } + if (bytes == null) + { + format = "image/bmp"; + obj = await clipboard.GetDataAsync(format); + bytes = obj as IEnumerable; + } + if (bytes == null) + { + format = "image/png"; + obj = await clipboard.GetDataAsync(format); + bytes = obj as IEnumerable; + } + if (bytes == null) + { + format = "image/jpeg"; + obj = await clipboard.GetDataAsync(format); + bytes = obj as IEnumerable; + } if (bytes != null) { var printable = bytes.Take(1000); var sb = new StringBuilder(256 + printable.Count() * 3); - sb.AppendLine($"{bytes.Count()} bytes, list of first {printable.Count()}"); + sb.AppendLine($"format: {format}, {bytes.Count()} bytes, list of first {printable.Count()}"); sb.AppendJoin(" ", printable.Select(x => x.ToString("X2"))); ClipboardContent.Text = sb.ToString(); }