diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 32a818284..3b0a04070 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -673,7 +673,7 @@ namespace Greenshot.Drawing { e.Effect=DragDropEffects.None; } else { List filenames = GetFilenames(e); - if ((filenames != null && filenames.Count > 0) || e.Data.GetDataPresent(DataFormats.Bitmap, true) || e.Data.GetDataPresent(DataFormats.EnhancedMetafile, true)) { + if ((filenames != null && filenames.Count > 0) || e.Data.GetDataPresent("DragImageBits") || e.Data.GetDataPresent(DataFormats.Bitmap, true) || e.Data.GetDataPresent(DataFormats.EnhancedMetafile, true)) { e.Effect=DragDropEffects.Copy; } else { e.Effect=DragDropEffects.None; @@ -684,6 +684,18 @@ namespace Greenshot.Drawing { private void OnDragDrop(object sender, DragEventArgs e) { List filenames = GetFilenames(e); Point mouse = this.PointToClient(new Point(e.X, e.Y)); + if (e.Data.GetDataPresent("Text")) { + string possibleUrl = (string)e.Data.GetData("Text"); + if (possibleUrl != null && possibleUrl.StartsWith("http")) { + using (Bitmap image = NetworkHelper.DownloadImage(possibleUrl)) { + if (image != null) { + AddBitmapContainer(image, mouse.X, mouse.Y); + return; + } + } + } + } + if ((filenames != null && filenames.Count > 0)) { foreach (string filename in filenames) { if (filename != null && filename.Trim().Length > 0) { diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index fd945f3d8..a69ef321a 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -1207,11 +1207,16 @@ namespace Greenshot { } Size imageSize = this.Surface.Image.Size; Size currentImageClientSize = this.panel1.ClientSize; - if (currentImageClientSize.Height > imageSize.Height && currentImageClientSize.Width > imageSize.Width) { + if (currentImageClientSize.Width > imageSize.Width) { + var canvas = this.Surface as Control; + if (canvas != null) { + canvas.Left = (currentImageClientSize.Width - imageSize.Width) / 2; + } + } + if (currentImageClientSize.Height > imageSize.Height) { var canvas = this.Surface as Control; if (canvas != null) { canvas.Top = (currentImageClientSize.Height - imageSize.Height) / 2; - canvas.Left = (currentImageClientSize.Width - imageSize.Width) / 2; } } } diff --git a/GreenshotPlugin/Core/NetworkHelper.cs b/GreenshotPlugin/Core/NetworkHelper.cs index 349c0f74d..9adb0089d 100644 --- a/GreenshotPlugin/Core/NetworkHelper.cs +++ b/GreenshotPlugin/Core/NetworkHelper.cs @@ -80,6 +80,27 @@ namespace GreenshotPlugin.Core { } return null; } + + /// + /// Download the url to Bitmap + /// + /// + /// Bitmap + public static Bitmap DownloadImage(string url) { + try { + HttpWebRequest request = (HttpWebRequest)NetworkHelper.CreateWebRequest(url); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + if (request.HaveResponse) { + using (Image image = Image.FromStream(response.GetResponseStream())) { + return new Bitmap(image); + } + } + + } catch (Exception e) { + LOG.Error("Problem downloading the image from: " + url, e); + } + return null; + } /// /// Helper method to create a web request, eventually with proxy