Tag: base64

Java BufferedImage到PNG格式的Base64字符串

我试图将屏幕截图输出作为base64编码的字符串,但没有得到很远。 到目前为止我的代码使用的是Base64库( http://iharder.sourceforge.net/current/java/base64/ ): Robot robot = new Robot(); Rectangle r = new Rectangle( Toolkit.getDefaultToolkit().getScreenSize() ); BufferedImage bi = robot.createScreenCapture(r); ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStream b64 = new Base64.OutputStream(os); ImageIO.write(bi, “png”, os); ByteArrayOutputStream out = new ByteArrayOutputStream(); out.writeTo(b64); String result = out.toString(“UTF-8”); 每次我运行它,“结果”总是一个空字符串,但我不明白为什么。 有任何想法吗? 注意:我不想将png写入磁盘上的文件。

使用base64图像的HTML到PDF会抛出FileNotFoundException

我正在使用itextpdf-5.0.6.jar(Java 8),当我尝试使用base64图像标记导出html代码时,我得到文件未找到exception。 如果我删除图像标记一切都很好! 我发现很少有关于覆盖图像标签处理器的解决方案,但是大多数都是旧的并且与5.0.6版本不兼容。 这是我发送的HTML: “\n\n\n \n Test PDF\n\n\n\n \n\n \n\n\n\n\n\n\nHellow world\n” 我的代码的一部分: fileOutputStream = new FileOutputStream(file); Document document = new Document(); PdfWriter.getInstance(document, fileOutputStream); document.open(); HTMLWorker htmlWorker = new HTMLWorker(document); StringReader stringReader = new StringReader(htmlCode); htmlWorker.parse(stringReader); document.close(); fileOutputStream.close(); 任何帮助都会被感谢

将文件编码为base64时内存不足

使用Apache commons的Base64 public byte[] encode(File file) throws FileNotFoundException, IOException { byte[] encoded; try (FileInputStream fin = new FileInputStream(file)) { byte fileContent[] = new byte[(int) file.length()]; fin.read(fileContent); encoded = Base64.encodeBase64(fileContent); } return encoded; } Exception in thread “AWT-EventQueue-0” java.lang.OutOfMemoryError: Java heap space at org.apache.commons.codec.binary.BaseNCodec.encode(BaseNCodec.java:342) at org.apache.commons.codec.binary.Base64.encodeBase64(Base64.java:657) at org.apache.commons.codec.binary.Base64.encodeBase64(Base64.java:622) at org.apache.commons.codec.binary.Base64.encodeBase64(Base64.java:604) 我正在为移动设备制作小应用程序。