-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WPF - StartDragging populate DataObject with Image #2687
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
using System.Windows.Controls.Primitives; | ||
using System.Windows.Input; | ||
using System.Windows.Interop; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Threading; | ||
using CefSharp.Enums; | ||
using CefSharp.Internals; | ||
|
@@ -785,16 +787,29 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo | |
currentDragData = dragData.Clone(); | ||
currentDragData.ResetFileContents(); | ||
|
||
// TODO: The following code block *should* handle images, but GetFileContents is | ||
// not yet implemented. | ||
//if (dragData.IsFile) | ||
//{ | ||
// var bmi = new BitmapImage(); | ||
// bmi.BeginInit(); | ||
// bmi.StreamSource = dragData.GetFileContents(); | ||
// bmi.EndInit(); | ||
// dataObject.SetImage(bmi); | ||
//} | ||
if (dragData.HasImage) | ||
{ | ||
IImage dragImage = dragData.Image; | ||
int width, height; | ||
byte[] pixels = dragImage.GetAsBitmap(1f, ColorType.Rgba8888, AlphaType.PreMultiplied, out width, out height); | ||
int stride = ((width * 32 + 31) & ~31) / 8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like your using
|
||
var bitmap = BitmapSource.Create(width, height, 96.0, 96.0, PixelFormats.Pbgra32, null, pixels, stride); | ||
bitmap.Freeze(); | ||
dataObject.SetImage(bitmap); | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed if you've added support for image. |
||
{ | ||
// TODO: The following code block *should* handle images, but GetFileContents is | ||
// not yet implemented. | ||
//if (dragData.IsFile) | ||
//{ | ||
// var bmi = new BitmapImage(); | ||
// bmi.BeginInit(); | ||
// bmi.StreamSource = dragData.GetFileContents(); | ||
// bmi.EndInit(); | ||
// dataObject.SetImage(bmi); | ||
//} | ||
} | ||
|
||
UiThreadRunAsync(delegate | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the scale factor be dynamic based on the display? I would have though so.