简体   繁体   中英

How to get dragover image from webView to Bitmap (UWP C#)

I want to drag&drop image on website to Canvas on Xaml. But it is not acceptable, because dragged data is not image data but html data. So I try to get dragover thumbnail image. But I don't know how to access dragover thumbnail image.

How can I access dragover thumbnail image. I want to know those code. 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.
    }

You can use the following code to get the BitmapImage from DragEventArgs

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) { }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM