mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 09:33:46 -07:00
Removed an unneeded clone, which I found while fixing a problem with copying images FROM an Outlook mail. The problem is that PNG is on the clipboard, but this image is cropped! Taking the Dib format solved the issue...
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2476 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
d7abc8ce93
commit
4a1655eff2
1 changed files with 28 additions and 14 deletions
|
@ -41,9 +41,14 @@ namespace GreenshotPlugin.Core {
|
||||||
private static readonly Object clipboardLockObject = new Object();
|
private static readonly Object clipboardLockObject = new Object();
|
||||||
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
private static readonly string FORMAT_FILECONTENTS = "FileContents";
|
private static readonly string FORMAT_FILECONTENTS = "FileContents";
|
||||||
private static readonly string FORMAT_JPG = "JPG";
|
|
||||||
private static readonly string FORMAT_PNG = "PNG";
|
private static readonly string FORMAT_PNG = "PNG";
|
||||||
|
private static readonly string FORMAT_PNG_OFFICEART = "PNG+Office Art";
|
||||||
|
private static readonly string FORMAT_JPG = "JPG";
|
||||||
|
private static readonly string FORMAT_JFIF = "JFIF";
|
||||||
|
private static readonly string FORMAT_JFIF_OFFICEART = "JFIF+Office Art";
|
||||||
private static readonly string FORMAT_GIF = "GIF";
|
private static readonly string FORMAT_GIF = "GIF";
|
||||||
|
private static readonly string FORMAT_BITMAP_PLACEHOLDER = "_BITMAP_";
|
||||||
|
|
||||||
private static IntPtr nextClipboardViewer = IntPtr.Zero;
|
private static IntPtr nextClipboardViewer = IntPtr.Zero;
|
||||||
// Template for the HTML Text on the clipboard
|
// Template for the HTML Text on the clipboard
|
||||||
// see: http://msdn.microsoft.com/en-us/library/ms649015%28v=vs.85%29.aspx
|
// see: http://msdn.microsoft.com/en-us/library/ms649015%28v=vs.85%29.aspx
|
||||||
|
@ -275,22 +280,17 @@ EndSelection:<<<<<<<4
|
||||||
/// <param name="dataObject"></param>
|
/// <param name="dataObject"></param>
|
||||||
/// <returns>IEnumerable<Image></returns>
|
/// <returns>IEnumerable<Image></returns>
|
||||||
public static IEnumerable<Image> GetImages(IDataObject dataObject) {
|
public static IEnumerable<Image> GetImages(IDataObject dataObject) {
|
||||||
Image tmpImage = null;
|
|
||||||
Image returnImage = null;
|
|
||||||
|
|
||||||
// Get single image, this takes the "best" match
|
// Get single image, this takes the "best" match
|
||||||
tmpImage = GetImage(dataObject);
|
Image singleImage = GetImage(dataObject);
|
||||||
if (tmpImage != null) {
|
if (singleImage != null) {
|
||||||
LOG.InfoFormat("Got image from clipboard with size {0} and format {1}", tmpImage.Size, tmpImage.PixelFormat);
|
LOG.InfoFormat("Got image from clipboard with size {0} and format {1}", singleImage.Size, singleImage.PixelFormat);
|
||||||
returnImage = ImageHelper.Clone(tmpImage);
|
yield return singleImage;
|
||||||
// Clean up.
|
|
||||||
tmpImage.Dispose();
|
|
||||||
yield return returnImage;
|
|
||||||
} else {
|
} else {
|
||||||
// check if files are supplied
|
// check if files are supplied
|
||||||
List<string> imageFiles = GetImageFilenames(dataObject);
|
List<string> imageFiles = GetImageFilenames(dataObject);
|
||||||
if (imageFiles != null) {
|
if (imageFiles != null) {
|
||||||
foreach (string imageFile in imageFiles) {
|
foreach (string imageFile in imageFiles) {
|
||||||
|
Image returnImage = null;
|
||||||
try {
|
try {
|
||||||
returnImage = ImageHelper.LoadImage(imageFile);
|
returnImage = ImageHelper.LoadImage(imageFile);
|
||||||
} catch (Exception streamImageEx) {
|
} catch (Exception streamImageEx) {
|
||||||
|
@ -314,9 +314,19 @@ 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};
|
string[] retrieveFormats;
|
||||||
|
|
||||||
|
// Found a weird bug, where PNG's from Outlook 2010 are clipped
|
||||||
|
// So I build some special logik to get the best format:
|
||||||
|
if (formats != null && formats.Contains(FORMAT_PNG_OFFICEART) && formats.Contains(DataFormats.Dib)) {
|
||||||
|
// Outlook ??
|
||||||
|
LOG.Info("Most likely the current clipboard contents come from Outlook, as this has a problem with PNG and others we place the DIB format to the front...");
|
||||||
|
retrieveFormats = new string[] { DataFormats.Dib, FORMAT_BITMAP_PLACEHOLDER, FORMAT_FILECONTENTS, FORMAT_PNG_OFFICEART, FORMAT_PNG, FORMAT_JFIF_OFFICEART, FORMAT_JPG, FORMAT_JFIF, DataFormats.Tiff, FORMAT_GIF };
|
||||||
|
} else {
|
||||||
|
retrieveFormats = new string[] { FORMAT_PNG_OFFICEART, FORMAT_PNG, FORMAT_JFIF_OFFICEART, FORMAT_JPG, FORMAT_JFIF, DataFormats.Tiff, DataFormats.Dib, FORMAT_BITMAP_PLACEHOLDER, FORMAT_FILECONTENTS, FORMAT_GIF };
|
||||||
|
}
|
||||||
foreach(string currentFormat in retrieveFormats) {
|
foreach(string currentFormat in retrieveFormats) {
|
||||||
if (string.IsNullOrEmpty(currentFormat)) {
|
if (FORMAT_BITMAP_PLACEHOLDER.Equals(currentFormat)) {
|
||||||
LOG.Info("Using default .NET Clipboard.GetImage()");
|
LOG.Info("Using default .NET Clipboard.GetImage()");
|
||||||
try {
|
try {
|
||||||
returnImage = Clipboard.GetImage();
|
returnImage = Clipboard.GetImage();
|
||||||
|
@ -411,7 +421,11 @@ EndSelection:<<<<<<<4
|
||||||
MemoryStream imageStream = GetFromDataObject(dataObject, format) as MemoryStream;
|
MemoryStream imageStream = GetFromDataObject(dataObject, format) as MemoryStream;
|
||||||
if (isValidStream(imageStream)) {
|
if (isValidStream(imageStream)) {
|
||||||
try {
|
try {
|
||||||
using (Image tmpImage = Image.FromStream(imageStream)) {
|
using (FileStream fs = new FileStream(@"C:\Localdata\test.png", FileMode.OpenOrCreate)) {
|
||||||
|
imageStream.WriteTo(fs);
|
||||||
|
}
|
||||||
|
imageStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
using (Image tmpImage = Image.FromStream(imageStream, true, true)) {
|
||||||
if (tmpImage != null) {
|
if (tmpImage != null) {
|
||||||
LOG.InfoFormat("Got image with clipboard format {0} from the clipboard.", format);
|
LOG.InfoFormat("Got image with clipboard format {0} from the clipboard.", format);
|
||||||
return ImageHelper.Clone(tmpImage);
|
return ImageHelper.Clone(tmpImage);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue