Александр Asked:2020-10-13 02:43:28 +0000 UTC2020-10-13 02:43:28 +0000 UTC 2020-10-13 02:43:28 +0000 UTC 将 ImageIcon 对象添加到 Word 文档 772 告诉我,在技术上是否可以使用 Apache Poi 将 ImageIcon 图像插入 Word 文档? java 1 个回答 Voted Best Answer Александр 2020-10-15T01:18:28Z2020-10-15T01:18:28Z 也许有人会帮助 XWPFDocument document = new XWPFDocument(); InputStream is = imageInput(foto); XWPFParagraph title = document.createParagraph(); XWPFRun run = title.createRun(); run.addPicture(is, Document.PICTURE_TYPE_GIF, "АЛПАТОВ", Units.toEMU(120), Units.toEMU(160)); is.close(); private InputStream imageInput(ImageIcon foto) { try { Image fotoImage = foto.getImage(); BufferedImage bufferedImage = new BufferedImage(fotoImage.getWidth(null), fotoImage.getHeight(null), BufferedImage.TYPE_INT_BGR); Graphics2D g2 = bufferedImage.createGraphics(); g2.drawImage(fotoImage, null, null); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "jpg", outputStream); InputStream is = new ByteArrayInputStream(outputStream.toByteArray()); return is; } catch (Exception e) { return null; } }
也许有人会帮助