mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 09:33:46 -07:00
Changes to clipboard code: log statement changes and consolidated some code.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2414 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
12c9e943b2
commit
6ec8ecfaa1
4 changed files with 89 additions and 90 deletions
|
@ -407,7 +407,7 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newImage"></param>
|
/// <param name="newImage"></param>
|
||||||
public Surface(Image newImage) : this() {
|
public Surface(Image newImage) : this() {
|
||||||
LOG.Debug("Got image with dimensions " + newImage.Width + "," + newImage.Height + " bpp: " + newImage.PixelFormat);
|
LOG.DebugFormat("Got image with dimensions {0} and format {1}", newImage.Size, newImage.PixelFormat);
|
||||||
SetImage(newImage, true);
|
SetImage(newImage, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,12 +227,14 @@ namespace Greenshot.Helpers {
|
||||||
conf.CaptureDelay = 0;
|
conf.CaptureDelay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allways capture Mousecursor, only show when needed
|
// Capture Mousecursor if we are not loading from file or clipboard, only show when needed
|
||||||
|
if (captureMode != CaptureMode.File && captureMode != CaptureMode.Clipboard) {
|
||||||
capture = WindowCapture.CaptureCursor(capture);
|
capture = WindowCapture.CaptureCursor(capture);
|
||||||
capture.CursorVisible = false;
|
if (captureMouseCursor) {
|
||||||
// Check if needed
|
|
||||||
if (captureMouseCursor && captureMode != CaptureMode.Clipboard && captureMode != CaptureMode.File) {
|
|
||||||
capture.CursorVisible = conf.CaptureMousepointer;
|
capture.CursorVisible = conf.CaptureMousepointer;
|
||||||
|
} else {
|
||||||
|
capture.CursorVisible = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(captureMode) {
|
switch(captureMode) {
|
||||||
|
@ -296,22 +298,14 @@ namespace Greenshot.Helpers {
|
||||||
HandleCapture();
|
HandleCapture();
|
||||||
break;
|
break;
|
||||||
case CaptureMode.Clipboard:
|
case CaptureMode.Clipboard:
|
||||||
Image clipboardImage = null;
|
Image clipboardImage = ClipboardHelper.GetImage();
|
||||||
string text = "Clipboard";
|
|
||||||
if (ClipboardHelper.ContainsImage()) {
|
|
||||||
clipboardImage = ClipboardHelper.GetImage();
|
|
||||||
}
|
|
||||||
if (clipboardImage != null) {
|
if (clipboardImage != null) {
|
||||||
if (capture != null) {
|
if (capture != null) {
|
||||||
capture.Image = clipboardImage;
|
capture.Image = clipboardImage;
|
||||||
} else {
|
} else {
|
||||||
capture = new Capture(clipboardImage);
|
capture = new Capture(clipboardImage);
|
||||||
}
|
}
|
||||||
string title = ClipboardHelper.GetText();
|
capture.CaptureDetails.Title = "Clipboard";
|
||||||
if (title == null || title.Trim().Length == 0) {
|
|
||||||
title = "Clipboard";
|
|
||||||
}
|
|
||||||
capture.CaptureDetails.Title = title;
|
|
||||||
capture.CaptureDetails.AddMetaData("source", "Clipboard");
|
capture.CaptureDetails.AddMetaData("source", "Clipboard");
|
||||||
// Force Editor, keep picker
|
// Force Editor, keep picker
|
||||||
if (capture.CaptureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION)) {
|
if (capture.CaptureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION)) {
|
||||||
|
@ -324,7 +318,7 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
HandleCapture();
|
HandleCapture();
|
||||||
} else {
|
} else {
|
||||||
MessageBox.Show("Couldn't create bitmap from : " + text);
|
MessageBox.Show(Language.GetString("clipboard_noimage"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CaptureMode.File:
|
case CaptureMode.File:
|
||||||
|
|
|
@ -281,6 +281,7 @@ EndSelection:<<<<<<<4
|
||||||
// Get single image, this takes the "best" match
|
// Get single image, this takes the "best" match
|
||||||
tmpImage = GetImage(dataObject);
|
tmpImage = GetImage(dataObject);
|
||||||
if (tmpImage != null) {
|
if (tmpImage != null) {
|
||||||
|
LOG.InfoFormat("Got image from clipboard with size {0} and format {1}", tmpImage.Size, tmpImage.PixelFormat);
|
||||||
returnImage = ImageHelper.Clone(tmpImage);
|
returnImage = ImageHelper.Clone(tmpImage);
|
||||||
// Clean up.
|
// Clean up.
|
||||||
tmpImage.Dispose();
|
tmpImage.Dispose();
|
||||||
|
@ -296,6 +297,7 @@ EndSelection:<<<<<<<4
|
||||||
LOG.Error("Problem retrieving Image from clipboard.", streamImageEx);
|
LOG.Error("Problem retrieving Image from clipboard.", streamImageEx);
|
||||||
}
|
}
|
||||||
if (returnImage != null) {
|
if (returnImage != null) {
|
||||||
|
LOG.InfoFormat("Got image from clipboard with size {0} and format {1}", tmpImage.Size, tmpImage.PixelFormat);
|
||||||
yield return returnImage;
|
yield return returnImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,34 +314,51 @@ EndSelection:<<<<<<<4
|
||||||
Image returnImage = null;
|
Image returnImage = null;
|
||||||
if (dataObject != null) {
|
if (dataObject != null) {
|
||||||
IList<string> formats = GetFormats(dataObject);
|
IList<string> formats = GetFormats(dataObject);
|
||||||
|
string[] retrieveFormats = {FORMAT_PNG, FORMAT_JPG, DataFormats.Tiff, DataFormats.Dib, FORMAT_FILECONTENTS, "", FORMAT_GIF};
|
||||||
|
foreach(string currentFormat in retrieveFormats) {
|
||||||
|
if (string.IsNullOrEmpty(currentFormat)) {
|
||||||
|
LOG.Info("Using default .NET Clipboard.GetImage()");
|
||||||
try {
|
try {
|
||||||
if (formats.Contains(FORMAT_PNG)) {
|
returnImage = Clipboard.GetImage();
|
||||||
returnImage = GetImageFormat(FORMAT_PNG, dataObject);
|
if (returnImage != null) {
|
||||||
|
return returnImage;
|
||||||
|
} else {
|
||||||
|
LOG.Info("Clipboard.GetImage() didn't return an image.");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.Error("Problem retrieving Image via Clipboard.GetImage(): ", ex);
|
||||||
|
}
|
||||||
|
} else if (formats.Contains(currentFormat)) {
|
||||||
|
LOG.InfoFormat("Found {0}, trying to retrieve.", currentFormat);
|
||||||
|
if (currentFormat == DataFormats.Dib) {
|
||||||
|
returnImage = GetDIBImage(dataObject);
|
||||||
|
} else {
|
||||||
|
returnImage = GetImageFormat(currentFormat, dataObject);
|
||||||
|
}
|
||||||
if (returnImage != null) {
|
if (returnImage != null) {
|
||||||
return returnImage;
|
return returnImage;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if (formats.Contains(FORMAT_JPG)) {
|
LOG.DebugFormat("Couldn't find format {0}.", currentFormat);
|
||||||
returnImage = GetImageFormat(FORMAT_JPG, dataObject);
|
|
||||||
if (returnImage != null) {
|
|
||||||
return returnImage;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (formats.Contains(DataFormats.Tiff)) {
|
|
||||||
returnImage = GetImageFormat(DataFormats.Tiff, dataObject);
|
|
||||||
if (returnImage != null) {
|
|
||||||
return returnImage;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the DIB readed should solve the issue reported here: https://sourceforge.net/projects/greenshot/forums/forum/676083/topic/6354353/index/page/1
|
/// <summary>
|
||||||
|
/// the DIB readed should solve the issue reported here: https://sourceforge.net/projects/greenshot/forums/forum/676083/topic/6354353/index/page/1
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Image</returns>
|
||||||
|
private static Image GetDIBImage(IDataObject dataObejct) {
|
||||||
try {
|
try {
|
||||||
// If the EnableSpecialDIBClipboardReader flag in the config is set, use the code from:
|
// If the EnableSpecialDIBClipboardReader flag in the config is set, use the code from:
|
||||||
// http://www.thomaslevesque.com/2009/02/05/wpf-paste-an-image-from-the-clipboard/
|
// http://www.thomaslevesque.com/2009/02/05/wpf-paste-an-image-from-the-clipboard/
|
||||||
// to read the DeviceIndependentBitmap from the clipboard, this might fix bug 3576125
|
// to read the DeviceIndependentBitmap from the clipboard, this might fix bug 3576125
|
||||||
if (config.EnableSpecialDIBClipboardReader && formats.Contains(DataFormats.Dib)) {
|
if (config.EnableSpecialDIBClipboardReader) {
|
||||||
MemoryStream dibStream = GetClipboardData(DataFormats.Dib) as MemoryStream;
|
MemoryStream dibStream = GetFromDataObject(dataObejct, DataFormats.Dib) as MemoryStream;
|
||||||
if (isValidStream(dibStream)) {
|
if (isValidStream(dibStream)) {
|
||||||
|
LOG.Info("Found valid DIB stream, trying to process it.");
|
||||||
byte[] dibBuffer = new byte[dibStream.Length];
|
byte[] dibBuffer = new byte[dibStream.Length];
|
||||||
dibStream.Read(dibBuffer, 0, dibBuffer.Length);
|
dibStream.Read(dibBuffer, 0, dibBuffer.Length);
|
||||||
BitmapInfoHeader infoHeader = BinaryStructHelper.FromByteArray<BitmapInfoHeader>(dibBuffer);
|
BitmapInfoHeader infoHeader = BinaryStructHelper.FromByteArray<BitmapInfoHeader>(dibBuffer);
|
||||||
|
@ -369,33 +388,16 @@ EndSelection:<<<<<<<4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LOG.InfoFormat("Skipping special DIB format reader for biCompression {0}", infoHeader.biCompression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LOG.Info("Skipping special DIB format reader as it's disabled in the configuration.");
|
||||||
}
|
}
|
||||||
} catch (Exception dibEx) {
|
} catch (Exception dibEx) {
|
||||||
LOG.Error("Problem retrieving DIB from clipboard.", dibEx);
|
LOG.Error("Problem retrieving DIB from clipboard.", dibEx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support for FileContents
|
|
||||||
returnImage = GetImageFormat(FORMAT_FILECONTENTS, dataObject);
|
|
||||||
if (returnImage != null) {
|
|
||||||
return returnImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
returnImage = Clipboard.GetImage();
|
|
||||||
if (returnImage != null) {
|
|
||||||
return returnImage;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.Error("Problem retrieving Image from clipboard.", ex);
|
|
||||||
}
|
|
||||||
if (formats.Contains(FORMAT_GIF)) {
|
|
||||||
returnImage = GetImageFormat(FORMAT_GIF, dataObject);
|
|
||||||
if (returnImage != null) {
|
|
||||||
return returnImage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,6 +413,7 @@ EndSelection:<<<<<<<4
|
||||||
try {
|
try {
|
||||||
using (Image tmpImage = Image.FromStream(imageStream)) {
|
using (Image tmpImage = Image.FromStream(imageStream)) {
|
||||||
if (tmpImage != null) {
|
if (tmpImage != null) {
|
||||||
|
LOG.InfoFormat("Got image with clipboard format {0} from the clipboard.", format);
|
||||||
return ImageHelper.Clone(tmpImage);
|
return ImageHelper.Clone(tmpImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -621,6 +624,7 @@ EndSelection:<<<<<<<4
|
||||||
formats = dataObj.GetFormats();
|
formats = dataObj.GetFormats();
|
||||||
}
|
}
|
||||||
if (formats != null) {
|
if (formats != null) {
|
||||||
|
LOG.DebugFormat("Got clipboard formats: {0}", String.Join(",", formats));
|
||||||
return new List<string>(formats);
|
return new List<string>(formats);
|
||||||
}
|
}
|
||||||
return new List<string>();
|
return new List<string>();
|
||||||
|
@ -715,7 +719,8 @@ EndSelection:<<<<<<<4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (Exception ex) {
|
||||||
|
LOG.Warn("Ignoring an issue with getting the dropFilenames from the clipboard: ", ex);
|
||||||
}
|
}
|
||||||
return filenames;
|
return filenames;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ namespace GreenshotPlugin.Core {
|
||||||
value.Dispose();
|
value.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG.Debug("Image is set with the following specifications: " + image.Width + "," + image.Height + " - " + image.PixelFormat);
|
LOG.DebugFormat("Image is set with the following specifications: {0} - {1}", image.Size, image.PixelFormat);
|
||||||
} else {
|
} else {
|
||||||
LOG.Debug("Image is removed.");
|
LOG.Debug("Image is removed.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue