Fixed a case with Drag & Drop of images where the transparency is gone. Also fixed the editor "Center" patch, this was only working when width & height were smaller.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2283 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-11-13 17:11:00 +00:00
commit a075a81daf
3 changed files with 41 additions and 3 deletions

View file

@ -673,7 +673,7 @@ namespace Greenshot.Drawing {
e.Effect=DragDropEffects.None; e.Effect=DragDropEffects.None;
} else { } else {
List<string> filenames = GetFilenames(e); List<string> 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; e.Effect=DragDropEffects.Copy;
} else { } else {
e.Effect=DragDropEffects.None; e.Effect=DragDropEffects.None;
@ -684,6 +684,18 @@ namespace Greenshot.Drawing {
private void OnDragDrop(object sender, DragEventArgs e) { private void OnDragDrop(object sender, DragEventArgs e) {
List<string> filenames = GetFilenames(e); List<string> filenames = GetFilenames(e);
Point mouse = this.PointToClient(new Point(e.X, e.Y)); 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)) { if ((filenames != null && filenames.Count > 0)) {
foreach (string filename in filenames) { foreach (string filename in filenames) {
if (filename != null && filename.Trim().Length > 0) { if (filename != null && filename.Trim().Length > 0) {

View file

@ -1207,13 +1207,18 @@ namespace Greenshot {
} }
Size imageSize = this.Surface.Image.Size; Size imageSize = this.Surface.Image.Size;
Size currentImageClientSize = this.panel1.ClientSize; 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; var canvas = this.Surface as Control;
if (canvas != null) { if (canvas != null) {
canvas.Top = (currentImageClientSize.Height - imageSize.Height) / 2;
canvas.Left = (currentImageClientSize.Width - imageSize.Width) / 2; 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;
}
}
} }
} }
} }

View file

@ -81,6 +81,27 @@ namespace GreenshotPlugin.Core {
return null; return null;
} }
/// <summary>
/// Download the url to Bitmap
/// </summary>
/// <param name="baseUri"></param>
/// <returns>Bitmap</returns>
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;
}
/// <summary> /// <summary>
/// Helper method to create a web request, eventually with proxy /// Helper method to create a web request, eventually with proxy
/// </summary> /// </summary>