HTML文本到图像并将blob另存为数据库

时间:2017-01-12 14:32:19

标签: java graphics bufferedimage javax.imageio

我已将富文本转换为图像并将其保存为db。从本地服务器(WINDOWS)创建Blob,但部署到应用程序服务器(LINUX)时。图像格式(字体,清晰度)发生了变化。我不确定我该做什么。请说清楚。这是我用过的代码。

        BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);      
            Graphics graphics = image.createGraphics();
            JEditorPane jep = new JEditorPane("text/html", html);
            jep.setSize(width, height);
            jep.print(graphics);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ImageIO.write(image, "png", new File("C:\\Dev\\img8_TYPE_INT_RGB.png"));
            ImageIO.write(image, "png", bos);

哪种图片格式适合文字内容?

提前致谢。

来自本地服务器的图像(WINDOWS)

enter image description here

来自Linux服务器(应用程序服务器)(Linux)的图像

enter image description here

1 个答案:

答案 0 :(得分:0)

我也使用过这段代码,但仍有同样的问题。

BufferedImage image = new BufferedImage(width, height,
                        BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();               
graphics.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
JEditorPane jep = new JEditorPane("text/html", html);
jep.setSize(width, height);
jep.print(graphics);