简体   繁体   中英

Clipboard copy from outlook always has black background set when retrieved as image from Java clipboard object

Here are the application steps

  1. copy some richtext from a html email message or from a website(a combination of text + image)
  2. In your java code retrieve the content copied from the clipboard object as BufferredImage
  3. Save the retrieved image object as image file on disk

You'll notice that in the saved file, the image comes fine, any non-black text appears fine but black text seems lost in the black background. Could not find a way to override the black background for the generated image. Some example code below.

     BufferedImage image = null;
try {
     image = (BufferedImage) transferable.getTransferData(DataFlavor.imageFlavor);

} catch (UnsupportedFlavorException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
      } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
}

saveImageToDisk(image);

      private void saveImageToDisk(BufferedImage image) {
    File outputFile = new File("c:\\image.png");
    try {
        ImageIO.write(image, "png", outputFile);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Found the solution - it is to use a custom system flavour which understands the mimetype of 'image\\x-emf'. strip first 8 bytes and write the remaining content as Bufferred image

Found the solution - it is to use a custom system flavour which understands the mimetype of 'image\\x-emf'. strip first 8 bytes and write the remaining content as Bufferred image

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