0
我有一個顯示字符串圖像的web端點...運行下面的代碼(在tomcat中)它會在任務欄中生成一個java圖標OSX。不知道這是一個問題,還是發生了什麼事。尋找某種explinationosx web服務在任務欄中生成圖標 - osx - 在繪製圖像時
@RequestMapping("/text/{text}")
public void textImage(HttpServletResponse response, @PathVariable("text") String text){
response.setContentType("image/png");
try{
OutputStream os = response.getOutputStream();
BufferedImage bufferedImage = new BufferedImage((text.length()*10) , 14, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.setBackground(Color.WHITE);
g2d.setPaint(Color.BLACK);
Font font = new Font("sansserif", Font.PLAIN, 12);
g2d.setFont(font);
g2d.drawString(text, 0, 12);
ImageIO.write(bufferedImage, "png", os);
} catch(Exception e) {
// nothing we can do, simply log the error
logger.error("Could not draw string: ", e);
}
}