简体   繁体   中英

Convert clipboard into a GIF/PNG when clipboard contains a picture

I was wondering if anybody knew a way to detect when a picture is copied in the clipboard then perform the following when it happens:

  • Convert this picture into a GIF/PNG
  • Then put back this compressed picture into the clipboard

The reason I am asking is that we often copy paste screenshots to users and paste them in Lotus. For some reason, pasting directly the picture in Lotus makes bigger emails than pasting in Paint saving as GIF, copying from the GIF then pasting in Lotus.

I guess than the clipboard does not store the pixels themselves but literally an object knowing the format of the data taken.

Feel free to correct me if I am wrong !

EDIT:

After the reading the first answer, my question is: "how can I, every time a picture is in the clipboard, compress it and put it back in the clipboard ?"

Assuming this is on Windows, the clipboard stores the image in non-compressed form. GIF is a compressed image file format, so it does compression which is why the files are smaller that way.

If you're only looking for a Lotus Notes solution, depending on which version of Lotus Notes you're running, there's a preference for "Compress images pasted into documents". I think that came in version 8.0 but I could be wrong. Apart from that, I don't know of anything you could use.

I just did a test of pasting a screenshot into a draft email and the saved draft is 124KB. Pasted the screenshot into Paint and saved it as a GIF which was a 163KB file.

I use the following C# program for a similar purpose. It saves the clipboard into a PNG file. Then I upload the file in Gmail or whatever.

class Clip2Png {
[System.STAThread]
public static void Main(string[] args) {
    if (args.Length != 1) {
        System.Console.WriteLine("Usage: clip2png filename");
        return;
    }

    System.Windows.Forms.IDataObject lData = System.Windows.Forms.Clipboard.GetDataObject();
    if (lData == null || !lData.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap)) {
        System.Console.WriteLine("No image in clipboard");
        return;
    }

    System.Drawing.Image image = (System.Drawing.Image)
            lData.GetData(System.Windows.Forms.DataFormats.Bitmap, true);
    image.Save(args[0], System.Drawing.Imaging.ImageFormat.Png);
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM