我有一个servlet已经调整大小并将图像编码为base64。我对其进行编码,这样回车问题从Java解码Base64并发送到浏览器
BufferedImage newBuf = .. a bufferedImage...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, sImgFormat, baos);
baos.flush();
imageInBytes = baos.toByteArray();
然后我编码到这一点的base64发送到浏览器这样
sun.misc.BASE64Encoder encoder = new BASE64Encoder();
String sEncImage = "data:image/jpg;base64," + encoder.encodeBuffer(imageInBytes);
浏览器将收到的编码和它的作品除了回车(“\ n“)一致地嵌入在破坏图像的字符串中。当我删除回车图像是好的。有没有一种方法来生成没有回车的编码。或者我必须在发回之前自行过滤掉它?
(我使用J2SE 1.4.2,需要继续这样做)
为什么不发送字节流? – Alanmars 2012-02-18 13:08:50
我需要发送base64文本到浏览器。另一端的HTML5 – giulio 2012-02-18 13:26:38
\ n不是回车符,它是换行符。 \ r是回车。 https://stackoverflow.com/questions/3091524/what-are-carriage-return-linefeed-and-form-feed – Achille 2017-12-28 16:48:42