System.Windows.Forms.Clipboard.GetImage()

Here are the examples of the csharp api class System.Windows.Forms.Clipboard.GetImage() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

24 Examples 7

1. Example

Project: StarryEyes
Source File: WinFormsClipboard.cs
View license
public static BitmapSource GetWpfImage()
        {
            return WinForms.Clipboard.GetImage().ToWpfBitmap();
        }

2. Example

Project: ShareX
Source File: ClipboardHelpers.cs
View license
public static Image GetImage()
        {
            try
            {
                lock (ClipboardLock)
                {
                    if (HelpersOptions.UseAlternativeGetImage)
                    {
                        return GetImageAlternative();
                    }

                    return Clipboard.GetImage();
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e, "Clipboard get image failed.");
            }

            return null;
        }

3. Example

Project: Clipboarder
Source File: MainFormPresenter.cs
View license
private ImageContent getImageContentFromClipboard() {
            ImageContent contentToReturn = new ImageContent();

            contentToReturn.index = view.ImageRowCount + 1;
            contentToReturn.image = Clipboard.GetImage();
            contentToReturn.time = System.DateTime.Now.ToShortTimeString();

            return contentToReturn;
        }

4. Example

Project: ShareX
Source File: ImageEffectsForm.cs
View license
private void tsmiLoadImageFromClipboard_Click(object sender, EventArgs e)
        {
            Image img = Clipboard.GetImage();

            if (img != null)
            {
                if (DefaultImage != null) DefaultImage.Dispose();
                DefaultImage = img;
                UpdatePreview();
            }
        }

5. Example

Project: GRBL-Plotter
Source File: GCodeFromImage.cs
View license
public void loadClipboard()
        {
            IDataObject iData = Clipboard.GetDataObject();
            if (iData.GetDataPresent(DataFormats.Bitmap))
            {
                lastFile = "";
                fileLoaded = true;
                loadedImage = new Bitmap(Clipboard.GetImage());
                originalImage = new Bitmap(Clipboard.GetImage());
                processLoading();
            }
        }

6. Example

View license
private void PasteButton_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (Clipboard.ContainsImage())
                {
                    this.unpackers.Clear();
                    this.DragAndDropLabel.Visible = false;
                    this.ControlsHelpLabel.Visible = false;
                    this.CreateUnpacker(new Bitmap(Clipboard.GetImage()), "clipboard");
                    this.StartUnpackers();
                }
                else
                {
                    MessageBox.Show("No image found in Clipboard");
                }
            }
            catch (Exception ex)
            {
                ForkandBeard.Logic.ExceptionHandler.HandleException(ex, "[email protected]");
            }
        }

7. Example

Project: ShareX
Source File: ClipboardHelper.cs
View license
private static Image GetImage(IDataObject dataObject)
        {
            Image returnImage = null/n ..... /n //View Source file for more details /n }

8. Example

Project: ShareX
Source File: TaskHelpers.cs
View license
public static void OpenImageEditor(string filePath = null)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                if (Clipboard.ContainsImage() &&
                    MessageBox.Show(Resources.TaskHelpers_OpenImageEditor_Your_clipboard_contains_image,
                    Resources.TaskHelpers_OpenImageEditor_Image_editor___How_to_load_image_, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    using (Image img = Clipboard.GetImage())
                    {
                        if (img != null)
                        {
                            AnnotateImage(img, null);
                            return;
                        }
                    }
                }

                filePath = ImageHelpers.OpenImageFileDialog();
            }

            if (!string.IsNullOrEmpty(filePath))
            {
                AnnotateImage(filePath);
            }
        }

9. Example

View license
public void IconClicked(HTMLEditorButtonArgs doc)
        {
            var image = Clipboard.GetImage();
            if (image != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    image.Save(memoryStream, ImageFormat.Png);
                    var base64 = Convert.ToBase64String(memoryStream.ToArray());
                    var html = string.Format("<img src=\"data:image/png;base64,{0}\" alt=\"{1}\" />", base64,
                        Guid.NewGuid());
                    var insertHtmlButton = new InsertHtmlButton(html);
                    insertHtmlButton.IconClicked(doc);
                }
            }
            else
            {
                MessageBox.Show(Resources.NoImageInClipboard, Resources.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

10. Example

Project: optimizer
Source File: Integrator.cs
View license
internal static string ExtractIconFromExecutable(string itemName, string fileName)
        {
            string iconPath = string.Empty;

            if (File.Exists(fileName))
            {
                Icon ico = Icon.ExtractAssociatedIcon(fileName);

                Clipboard.SetImage(ico.ToBitmap());
                Clipboard.GetImage().Save(Required.ExtractedIcons + "\\" + itemName + ".ico", ImageFormat.Bmp);
                Clipboard.Clear();

                iconPath = Required.ExtractedIcons + "\\" + itemName + ".ico";
            }

            return iconPath;
        }

11. Example

View license
private static IList<object> LoadClipboardPicture()
        {
            try
            {
                Logger.Log("Load clipboard begins.");
                var result = new List<object>();
                if (Clipboard.ContainsImage())
                {
                    result.Add(Clipboard.GetImage());
                }
                if (Clipboard.ContainsFileDropList())
                {
                    result.Add(Clipboard.GetFileDropList());
                }
                if (Clipboard.ContainsText())
                {
                    result.Add(Clipboard.GetText());
                }
                Logger.Log("Load clipboard done.");
                return result;
            }
            catch (Exception e)
            {
                // sometimes Clipboard may fail
                Logger.LogException(e, "LoadClipboardPicture");
                return new List<object>();
            }
        }

12. Example

Project: Xploit
Source File: BinaryFromScreen.cs
View license
Bitmap GetBitmap()
        {
            switch (CaptureMethod)
            {
                case ECapture.Clipboard:
                    {
                        while (!Clipboard.ContainsImage())
                            Thread.Sleep(50);

                        Bitmap ret = (Bitmap)Clipboard.GetImage();
                        Clipboard.Clear();
                        return ret;
                    }
                case ECapture.ScreenShoot:
                    {
                        Rectangle bounds = Screen.GetBounds(Point.Empty);
                        Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
                        using (Graphics g = Graphics.FromImage(bitmap))
                        {
                            g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                        }
                        return bitmap;
                    }
            }
            return null;
        }

13. Example

Project: Dithering
Source File: ClipboardHelpers.cs
View license
public static Bitmap GetImage()
    {
      Bitmap result;

      // http://csharphelper.com/blog/2014/09/paste-a-png-format-image-with-a-transparent-background-from-the-clipboard-in-c/

      result = null;

      try
      {
        if (Clipboard.ContainsData(PngFormat))
        {
          object data;

          data = Clipboard.GetData(PngFormat);

          if (data != null)
          {
            Stream stream;

            stream = data as MemoryStream;

            if (stream == null)
            {
              byte[] buffer;

              buffer = data as byte[];

              if (buffer != null)
              {
                stream = new MemoryStream(buffer);
              }
            }

            if (stream != null)
            {
              result = Image.FromStream(stream).Copy();

              stream.Dispose();
            }
          }
        }

        if (result == null)
        {
          result = (Bitmap)Clipboard.GetImage();
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(string.Format("Failed to obtain image. {0}", ex.GetBaseException().Message), "Paste Image", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }

      return result;
    }

14. Example

Project: DNTLive
Source File: MainForm.cs
View license
private void btnImg_Click(object sender, EventArgs e)
        {
            int i = 0;
            var imgObj = Clipboard.GetImage();
            var dataStr = GetHtmlStr();
            int fileCount = GetFileDrop();
            if (imgObj != null)//?HTML?????
            {
                CreateDirectory("Images");
                imgObj.Save(string.Format(@"Images\{0}.png", GetNewName()), ImageFormat.Png);
                MessageBox.Show("???????Images????", "??????");
                OpenDirectory();
            }
            else if (!string.IsNullOrEmpty(dataStr))
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();
                i = DownloadImg(dataStr);
                watch.Stop();
                MessageBox.Show(string.Format("????{0}???,??{1}????Images???", i, watch.Elapsed), "??????");
                OpenDirectory();
            }
            else if (fileCount > 0)
            {
                MessageBox.Show(string.Format("????{0}???,???Images???", fileCount), "??????");
                OpenDirectory();
            }
            else
            {
                MessageBox.Show("??????????", "??????");
            }
        }

15. Example

Project: Toxy
Source File: ClipboardContentViewer.cs
View license
private void ClipboardContentViewer_Load(object sender, EventArgs e)
        {
            pbClipboa/n ..... /n //View Source file for more details /n }

16. Example

Project: upScreen
Source File: CaptureControl.cs
View license
public static void GetFromClipboard()
        {
            Image image = null;

            // Load the image from a copied image
            if (Clipboard.ContainsImage())
            {
                Log.Write(l.Info, "Clipboard mode, copied image");
                image = Clipboard.GetImage();
            }
            // Load the image from a copied image file
            else if (Clipboard.ContainsFileDropList())
            {
                Log.Write(l.Info, "Clipboard mode, file list");
                foreach (var localFile in Clipboard.GetFileDropList())
                {
                    SaveImage(localFile);
                }
                // raise CaptureComplete to start uploading
                CaptureComplete(null, EventArgs.Empty);
            }
            // Load the image from a copied image url
            else if (Common.ImageUrlInClipboard)
            {
                var url = Clipboard.GetText();
                Log.Write(l.Info, $"Clipboard mode, url: {url}");
                image = GetFromUrl(url);
            }

            // Prevent null reference exception
            if (image == null) return;

            Common.OtherFormOpen = true;

            SaveImage(image);
        }

17. Example

Project: ShareX
Source File: ClipboardContentViewer.cs
View license
private void ClipboardContentViewer_Load(object sender, EventArgs e)
        {
            pbClipboa/n ..... /n //View Source file for more details /n }

18. Example

View license
private void HandlePastedPicture(bool isUsingWinformMsgBox = false)
        {
            try
      /n ..... /n //View Source file for more details /n }

19. Example

Project: ImageGlass
Source File: frmMain.cs
View license
private void mnuMainOpenImageData_Click(object sender, EventArgs e)
        {
            //Is there/n ..... /n //View Source file for more details /n }

20. Example

Project: noterium
Source File: ClipboardHelper.cs
View license
public static Image GetImageFromClipboard()
        {
            var dataObject = Clipboard.GetDataObject();
            if (dataObject == null)
                return null;

            if (dataObject.GetDataPresent(DataFormats.Dib))
            {
                var dib = ((MemoryStream) Clipboard.GetData(DataFormats.Dib)).ToArray();
                var width = BitConverter.ToInt32(dib, 4);
                var height = BitConverter.ToInt32(dib, 8);
                var bpp = BitConverter.ToInt16(dib, 14);
                if (bpp == 32)
                {
                    var gch = GCHandle.Alloc(dib, GCHandleType.Pinned);
                    Bitmap bmp = null;
                    try
                    {
                        var ptr = new IntPtr((long) gch.AddrOfPinnedObject() + 40);
                        bmp = new Bitmap(width, height, width*4, PixelFormat.Format32bppArgb, ptr);

                        var newBmp = new Bitmap(bmp);
                        newBmp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        return newBmp;
                    }
                    finally
                    {
                        gch.Free();
                        bmp?.Dispose();
                    }
                }
            }

            return Clipboard.ContainsImage() ? Clipboard.GetImage() : null;
        }

21. Example

Project: Pscx
Source File: GetClipboardCommand.cs
View license
void GetClipboardContents()
        {
            if (_image)
            {
                if (WinF/n ..... /n //View Source file for more details /n }

22. Example

Project: KeeThief
Source File: ClipboardUtil.cs
View license
public static byte[] ComputeHash()
		{
			try // This works always or never
			{
				bool bOpened = /n ..... /n //View Source file for more details /n }

23. Example

Project: ZXing.Net
Source File: Program.cs
View license
[STAThread]
      static void Main(string[] args)
      {
         if (args.Length == 0)
         {
/n ..... /n //View Source file for more details /n }

24. Example

Project: ShareX
Source File: UploadManager.cs
View license
public static void ClipboardUpload(TaskSettings taskSettings = null)
        {
            if (taskS/n ..... /n //View Source file for more details /n }