Skip to content

Commit 9c2c3b2

Browse files
authored
Merge d9f522b into ea843f3
2 parents ea843f3 + d9f522b commit 9c2c3b2

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;
@@ -785,16 +787,29 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo
785787
currentDragData = dragData.Clone();
786788
currentDragData.ResetFileContents();
787789

788-
// TODO: The following code block *should* handle images, but GetFileContents is
789-
// not yet implemented.
790-
//if (dragData.IsFile)
791-
//{
792-
// var bmi = new BitmapImage();
793-
// bmi.BeginInit();
794-
// bmi.StreamSource = dragData.GetFileContents();
795-
// bmi.EndInit();
796-
// dataObject.SetImage(bmi);
797-
//}
790+
if (dragData.HasImage)
791+
{
792+
IImage dragImage = dragData.Image;
793+
int width, height;
794+
byte[] pixels = dragImage.GetAsBitmap(1f, ColorType.Rgba8888, AlphaType.PreMultiplied, out width, out height);
795+
int stride = ((width * 32 + 31) & ~31) / 8;
796+
var bitmap = BitmapSource.Create(width, height, 96.0, 96.0, PixelFormats.Pbgra32, null, pixels, stride);
797+
bitmap.Freeze();
798+
dataObject.SetImage(bitmap);
799+
}
800+
else
801+
{
802+
// TODO: The following code block *should* handle images, but GetFileContents is
803+
// not yet implemented.
804+
//if (dragData.IsFile)
805+
//{
806+
// var bmi = new BitmapImage();
807+
// bmi.BeginInit();
808+
// bmi.StreamSource = dragData.GetFileContents();
809+
// bmi.EndInit();
810+
// dataObject.SetImage(bmi);
811+
//}
812+
}
798813

799814
UiThreadRunAsync(delegate
800815
{

0 commit comments

Comments
 (0)