osx web 服务在任务栏中生成图标 - osx - 绘制图像时
我有一个显示字符串图像的 Web 端点...当运行以下代码(在 tomcat 中)时,它会在 OSX 上的任务栏中生成一个 java 图标。不确定这是否是一个问题,或者发生了什么。寻找某种解释
@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);
}
}
I have a web endpoint that displays an image of a string... When the following code is run (in tomcat) it spawns a java icon in the taskbar on OSX. Not sure if it is a problem, or whats going on. Looking for some sort of explination
@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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,当您使用图形时,您会获得窗口服务器连接(无论您是否实际渲染到屏幕)。您可以使用无头模式来避免它。
By default when you use graphics, you get a window server connection (whether or not you're actually rendering to the screen). You can use headless mode to avoid it.