Esempio n. 1
0
 public string SaveToTmpFile(Image img, OutputFormat outputFormat, int quality, bool reduceColors)
 {
     return(ImageOutput.SaveToTmpFile(img, outputFormat, quality, reduceColors));
 }
Esempio n. 2
0
        public static void SetClipboardData(Image image)
        {
            CleanupTmpFile();
            DataObject ido = new DataObject();

            // This will work for Office and most other applications
            //ido.SetData(DataFormats.Bitmap, true, image);

            MemoryStream bmpStream   = null;
            MemoryStream imageStream = null;
            MemoryStream pngStream   = null;

            try {
                if (config.ClipboardFormats.Contains(ClipboardFormat.PNG))
                {
                    pngStream = new MemoryStream();
                    // PNG works for Powerpoint
                    image.Save(pngStream, ImageFormat.Png);
                    // Set the PNG stream
                    ido.SetData("PNG", false, pngStream);
                }


                if (config.ClipboardFormats.Contains(ClipboardFormat.HTML))
                {
                    bmpStream = new MemoryStream();
                    // Save image as BMP
                    image.Save(bmpStream, ImageFormat.Bmp);

                    imageStream = new MemoryStream();
                    // Copy the source, but skip the "BITMAPFILEHEADER" which has a size of 14
                    imageStream.Write(bmpStream.GetBuffer(), BITMAPFILEHEADER_LENGTH, (int)bmpStream.Length - BITMAPFILEHEADER_LENGTH);

                    // Set the DIB to the clipboard DataObject
                    ido.SetData(DataFormats.Dib, true, imageStream);
                }

                // Set the HTML
                if (config.ClipboardFormats.Contains(ClipboardFormat.HTML))
                {
                    // Mark the clipboard for us as "do not touch"
                    ido.SetData("greenshot", false, "was here!");
                    previousTmpFile = ImageOutput.SaveToTmpFile(image);
                    string html = getClipboardString(image, previousTmpFile);
                    ido.SetText(html, TextDataFormat.Html);
                }
            } finally {
                // we need to use the SetDataOject before the streams are closed otherwise the buffer will be gone!
                // Place the DataObject to the clipboard
                SetDataObject(ido);

                if (pngStream != null)
                {
                    pngStream.Dispose();
                    pngStream = null;
                }

                if (bmpStream != null)
                {
                    bmpStream.Dispose();
                    bmpStream = null;
                }

                if (imageStream != null)
                {
                    imageStream.Dispose();
                    imageStream = null;
                }
            }
        }
        public static void SetClipboardData(Image image)
        {
            DataObject ido = new DataObject();

            // This will work for Office and most other applications
            //ido.SetData(DataFormats.Bitmap, true, image);

            MemoryStream bmpStream   = null;
            MemoryStream imageStream = null;
            MemoryStream pngStream   = null;

            try {
                // Create PNG stream
                if (config.ClipboardFormats.Contains(ClipboardFormat.PNG) || config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL))
                {
                    pngStream = new MemoryStream();
                    // PNG works for Powerpoint
                    image.Save(pngStream, ImageFormat.Png);
                    pngStream.Seek(0, SeekOrigin.Begin);
                }

                if (config.ClipboardFormats.Contains(ClipboardFormat.PNG))
                {
                    // Set the PNG stream
                    ido.SetData("PNG", false, pngStream);
                }

                if (config.ClipboardFormats.Contains(ClipboardFormat.DIB))
                {
                    bmpStream = new MemoryStream();
                    // Save image as BMP
                    image.Save(bmpStream, ImageFormat.Bmp);
                    imageStream = new MemoryStream();
                    // Copy the source, but skip the "BITMAPFILEHEADER" which has a size of 14
                    imageStream.Write(bmpStream.GetBuffer(), BITMAPFILEHEADER_LENGTH, (int)bmpStream.Length - BITMAPFILEHEADER_LENGTH);

                    // Set the DIB to the clipboard DataObject
                    ido.SetData(DataFormats.Dib, true, imageStream);
                }

                // Set the HTML
                if (config.ClipboardFormats.Contains(ClipboardFormat.HTML))
                {
                    string tmpFile = ImageOutput.SaveToTmpFile(image, OutputFormat.png, config.OutputFileJpegQuality, config.OutputFileReduceColors);
                    string html    = getHTMLString(image, tmpFile);
                    ido.SetText(html, TextDataFormat.Html);
                }
                else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL))
                {
                    string html = getHTMLDataURLString(image, pngStream);
                    ido.SetText(html, TextDataFormat.Html);
                }
            } finally {
                // we need to use the SetDataOject before the streams are closed otherwise the buffer will be gone!
                // Place the DataObject to the clipboard
                SetDataObject(ido);

                if (pngStream != null)
                {
                    pngStream.Dispose();
                    pngStream = null;
                }

                if (bmpStream != null)
                {
                    bmpStream.Dispose();
                    bmpStream = null;
                }

                if (imageStream != null)
                {
                    imageStream.Dispose();
                    imageStream = null;
                }
            }
        }