Skip to content

Commit c31b43d

Browse files
authored
Merge ee0749a into 7436d64
2 parents 7436d64 + ee0749a commit c31b43d

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

CefSharp.Wpf/ChromiumWebBrowser.cs

+25-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System.Windows.Controls.Primitives;
1212
using System.Windows.Input;
1313
using System.Windows.Interop;
14+
using System.Windows.Media;
15+
using System.Windows.Media.Imaging;
1416
using System.Windows.Threading;
1517
using CefSharp.Enums;
1618
using CefSharp.Internals;
@@ -745,16 +747,29 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo
745747
currentDragData = dragData.Clone();
746748
currentDragData.ResetFileContents();
747749

748-
// TODO: The following code block *should* handle images, but GetFileContents is
749-
// not yet implemented.
750-
//if (dragData.IsFile)
751-
//{
752-
// var bmi = new BitmapImage();
753-
// bmi.BeginInit();
754-
// bmi.StreamSource = dragData.GetFileContents();
755-
// bmi.EndInit();
756-
// dataObject.SetImage(bmi);
757-
//}
750+
if (dragData.HasImage)
751+
{
752+
IImage dragImage = dragData.Image;
753+
int width, height;
754+
byte[] pixels = dragImage.GetAsBitmap(1f, ColorType.Rgba8888, AlphaType.PreMultiplied, out width, out height);
755+
int stride = ((width * 32 + 31) & ~31) / 8;
756+
var bitmap = BitmapSource.Create(width, height, 96.0, 96.0, PixelFormats.Pbgra32, null, pixels, stride);
757+
bitmap.Freeze();
758+
dataObject.SetImage(bitmap);
759+
}
760+
else
761+
{
762+
// TODO: The following code block *should* handle images, but GetFileContents is
763+
// not yet implemented.
764+
//if (dragData.IsFile)
765+
//{
766+
// var bmi = new BitmapImage();
767+
// bmi.BeginInit();
768+
// bmi.StreamSource = dragData.GetFileContents();
769+
// bmi.EndInit();
770+
// dataObject.SetImage(bmi);
771+
//}
772+
}
758773

759774
UiThreadRunAsync(delegate
760775
{

0 commit comments

Comments
 (0)