问题描述
我正在尝试将 html 文本转换为 png 或 jpg 图像。当我调用我的网络服务时,我有一个图像返回给我,文本有点模糊。它不是很尖锐。
方法:
@Transactional
@GetMapping("/media/image/{fun}")
public void getimageAsByteArray(HttpServletResponse response) throws IOException
{
Fiche fiche = ficheRepository.getone(23L);
response.setContentType(MediaType.IMAGE_PNG_VALUE);
String html = "<p>Ma <strong>description dcdvd</strong></p><p> </p><p><i><strong>dddddd</strong></i></p>";
Document doc = Jsoup.parse(html);
int width = 200,height = 100;
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
Graphics graphics = image.createGraphics();
JEditorPane jep = new JEditorPane("text/html",fiche.getTexte());
jep.setSize(width,height);
jep.print(graphics);
ImageIO.write(image,"png",response.getoutputStream());
}
结果: result.png
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)