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

只谈情不闲聊 提交于 2020-01-21 10:05:13

问题


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



来源:https://stackoverflow.com/questions/15977001/clipboard-copy-from-outlook-always-has-black-background-set-when-retrieved-as-im

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!