【问题标题】:How to get dragover image from webView to Bitmap (UWP C#)如何将拖动图像从 webView 获取到位图(UWP C#)
【发布时间】:2018-02-09 14:39:33
【问题描述】:

我想将网站上的图像拖放到 Xaml 上的 Canvas。 但这是不可接受的,因为拖动的数据不是图像数据而是html数据。 所以我尝试获取拖动缩略图。 但我不知道如何访问拖动缩略图。

如何访问拖拽缩略图。我想知道那些代码。 C#。

--Xaml--

    <WebView x:Name="WebView" Source="https://google.com" ScriptNotify="Notify" NavigationCompleted="Completed" ></WebView>
    <Canvas x:Name="Board" AllowDrop="True" DragOver="dragOver" Drop="drop" Background="White"></Canvas>

--C#--

    private void dragOver(object sender, DragEventArgs e)
    {
        e.AcceptedOperation = DataPackageOperation.Copy;
        e.DragUIOverride.IsContentVisible = true; // I want to get this content data. To bitmap.
    }

【问题讨论】:

  • 你能包含一个示例“html数据”吗?
  • 我添加示例代码。但它不是“html 数据”而是“Xaml 数据”。
  • 拖动时会自动获取缩略图。我想我没有理解您的要求。
  • 感谢您的评论。我想将缩略图图像转换为位图图像。用于在画布上粘贴。

标签: c# image xaml webview uwp


【解决方案1】:

您可以使用以下代码从DragEventArgs获取BitmapImage

if (e.DataView.Contains(StandardDataFormats.Bitmap))
{
    try
    {
        var a = await e.DataView.GetBitmapAsync();
        var c = await a.OpenReadAsync();
        BitmapImage b = new BitmapImage();
        b.SetSource(c);
        MyCanvasImage.Source = b;
    }
    catch (Exception) { }
}

【讨论】:

  • 对不起。我不能这样。来自 webView 的缩略图不是“StandardDataFormats.Bitmap”。所以这段代码没有运行......可能来自 webView 的缩略图是“StandardDataFormats.Html”。但我无法将“standardDataFormats.html”转换为位图图像...
  • @Tarou 你能在你的帖子中包含一个示例“html”吗?
  • 感谢 Vijay 每次。我使用 Google.com 的网站。所以它不是样本“HTML”数据。我将图像从 webView 上的谷歌搜索结果拖到画布上。我拖动图像,但它变成了 URL 数据。例如,我将图像拖到桌面,拖放的数据变为链接。所以“StandardDataFormats.Bitmap”不起作用。可能浏览器是Edge。 webView 引擎也是 Edge。
  • @Tarou 你的意思是谷歌的图片搜索吗?
  • 是的,我的意思是谷歌中的图片搜索或其他网站上的一些图片。
猜你喜欢
  • 1970-01-01
  • 2018-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多