private static Bitmap GetImageAlternative2() { IDataObject dataObject = Clipboard.GetDataObject(); if (dataObject != null) { string[] dataFormats = dataObject.GetFormats(false); if (dataFormats.Contains(FORMAT_PNG)) { using (MemoryStream ms = dataObject.GetData(FORMAT_PNG) as MemoryStream) { if (ms != null) { using (Bitmap bmp = new Bitmap(ms)) { return(ClipboardHelpersEx.CloneImage(bmp)); } } } } else if (dataFormats.Contains(DataFormats.Dib)) { using (MemoryStream ms = dataObject.GetData(DataFormats.Dib) as MemoryStream) { if (ms != null) { return(ClipboardHelpersEx.ImageFromClipboardDib(ms.ToArray())); } } } else if (dataFormats.Contains(FORMAT_17)) { using (MemoryStream ms = dataObject.GetData(FORMAT_17) as MemoryStream) { if (ms != null) { return(ClipboardHelpersEx.DIBV5ToBitmap(ms.ToArray())); } } } else if (dataFormats.Contains(DataFormats.Bitmap)) { return(dataObject.GetData(DataFormats.Bitmap, true) as Bitmap); } } return(null); }
private void UpdateSelectedClipboardContent() { ResetSelected(); if (lvClipboardContentList.SelectedItems.Count > 0) { ListViewItem lvi = lvClipboardContentList.SelectedItems[0]; string format = lvi.Text; if (CurrentDataObject != null) { object data = CurrentDataObject.GetData(format); if (data == null) { RefreshClipboardContentList(); } else { try { switch (data) { case MemoryStream ms: if (format.Equals(ClipboardHelpers.FORMAT_PNG, StringComparison.OrdinalIgnoreCase)) { using (Bitmap bmp = new Bitmap(ms)) { Bitmap clonedImage = ClipboardHelpersEx.CloneImage(bmp); LoadImage(clonedImage); } } else if (format.Equals(DataFormats.Dib, StringComparison.OrdinalIgnoreCase)) { Bitmap bmp = ClipboardHelpersEx.ImageFromClipboardDib(ms.ToArray()); LoadImage(bmp); } else if (format.Equals(ClipboardHelpers.FORMAT_17, StringComparison.OrdinalIgnoreCase)) { Bitmap bmp = ClipboardHelpersEx.DIBV5ToBitmap(ms.ToArray()); LoadImage(bmp); } else { LoadText(data.ToString()); } break; case Bitmap bmp: LoadImage(bmp); break; default: LoadText(data.ToString()); break; } } catch (Exception e) { e.ShowError(); } } } } }