当从Java剪贴板对象检索为图像时,outlook中的剪贴板副本始终具有黑色背景设置 [英] Clipboard copy from outlook always has black background set when retrieved as image from Java clipboard object

查看:146
本文介绍了当从Java剪贴板对象检索为图像时,outlook中的剪贴板副本始终具有黑色背景设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是申请步骤


  1. 从html电子邮件或网站复制一些richtext(文本+图像的组合)

  2. 在您的java代码中检索从剪贴板对象复制的内容为BufferredImage

  3. 将检索到的图像对象保存为磁盘上的图像文件

您会注意到,在保存的文件中,图像正常,任何非黑色文本都显示正常,但黑色背景中的黑色文字似乎丢失。找不到覆盖生成图像的黑色背景的方法。下面是一些示例代码。

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();
    }

}

找到解决方案 - 它是使用自定义系统风格,它可以理解'image \ x-emf'的mimetype。剥离前8个字节并将剩余内容写为Bufferred图像

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

推荐答案

找到解决方案 - 它是使用自定义系统风格理解'image \ x-emf'的模仿类型。剥离前8个字节并将剩余内容写为Bufferred图像

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

这篇关于当从Java剪贴板对象检索为图像时,outlook中的剪贴板副本始终具有黑色背景设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆