|
11 | 11 | using System.Windows.Controls.Primitives; |
12 | 12 | using System.Windows.Input; |
13 | 13 | using System.Windows.Interop; |
| 14 | +using System.Windows.Media; |
| 15 | +using System.Windows.Media.Imaging; |
14 | 16 | using System.Windows.Threading; |
15 | 17 | using CefSharp.Enums; |
16 | 18 | using CefSharp.Internals; |
@@ -745,16 +747,29 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo |
745 | 747 | currentDragData = dragData.Clone(); |
746 | 748 | currentDragData.ResetFileContents(); |
747 | 749 |
|
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 | + } |
758 | 773 |
|
759 | 774 | UiThreadRunAsync(delegate |
760 | 775 | { |
|
0 commit comments