|
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;
|
@@ -785,16 +787,29 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo
|
785 | 787 | currentDragData = dragData.Clone();
|
786 | 788 | currentDragData.ResetFileContents();
|
787 | 789 |
|
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 | + } |
798 | 813 |
|
799 | 814 | UiThreadRunAsync(delegate
|
800 | 815 | {
|
|
0 commit comments