Clipboard copy from outlook always has black backg

2019-02-20 04:07发布

问题:

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

回答1:

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