public ImageWrapper(Image image) { // Make sure the orientation is set correctly so Greenshot can process the image correctly ImageHelper.Orientate(image); _image = image; Width = _image.Width; Height = _image.Height; }
/// <summary> /// Get an Image from the IDataObject, don't check for FileDrop /// </summary> /// <param name="dataObject"></param> /// <returns>Image or null</returns> private static Image GetImage(IDataObject dataObject) { Image returnImage = null; if (dataObject != null) { IList <string> formats = GetFormats(dataObject); 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, 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_17, FORMAT_JFIF_OFFICEART, FORMAT_JPG, FORMAT_JFIF, DataFormats.Tiff, DataFormats.Dib, FORMAT_BITMAP, FORMAT_FILECONTENTS, FORMAT_GIF }; } foreach (string currentFormat in retrieveFormats) { if (formats.Contains(currentFormat)) { LOG.InfoFormat("Found {0}, trying to retrieve.", currentFormat); returnImage = GetImageForFormat(currentFormat, dataObject); } else { LOG.DebugFormat("Couldn't find format {0}.", currentFormat); } if (returnImage != null) { ImageHelper.Orientate(returnImage); return(returnImage); } } } return(null); }
/// <summary> /// Get an Image from the IDataObject, don't check for FileDrop /// </summary> /// <param name="dataObject"></param> /// <returns>Image or null</returns> private static Image GetImage(IDataObject dataObject) { Image returnImage = null; if (dataObject != null) { IList <string> formats = GetFormats(dataObject); 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) { if (FORMAT_BITMAP_PLACEHOLDER.Equals(currentFormat)) { LOG.Info("Using default .NET Clipboard.GetImage()"); try { returnImage = Clipboard.GetImage(); 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) { ImageHelper.Orientate(returnImage); return(returnImage); } } else { LOG.DebugFormat("Couldn't find format {0}.", currentFormat); } } } return(null); }