2017-01-12 33 views
0

我已將富文本轉換爲圖像並將其保存爲數據塊。 Blob從本地服務器(WINDOWS)創建,但部署到應用程序服務器(LINUX)。圖像格式(字體,清晰度)發生了變化。我不知道我必須做什麼。請說明一下。這是我使用的代碼。HTML文本圖像並保存爲Blob到數據庫

 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

+0

指定兩種圖像格式,用於寫入(Windows特定的)文件的JPEG和用於寫入內存中的流的GIF。你是什​​麼意思*「圖像格式(字體,清晰度)發生了變化」*?如果您與Windows和Linux輸出結果進行比較,可能會更容易理解/可視化。由於您使用了一個Swing組件('JEditorPane'),因此對於Windows和Linux(Gnome/KDE /其他)有不同的「外觀和感覺」,所以字體/抗鋸齒很可能會發生變化。您可以通過跨平臺的外觀和感覺來解決這個問題。 – haraldK

+0

我在這裏複製的圖像都是.png從本地輸入一個,從服務器輸入一個,並使用BufferedImage.TYPE_INT_RGB。讓我編輯我的代碼。 – Harish

+0

以前存儲的字體和清晰度是什麼,它是否也顯示在「JEditorPane」中? – NESPowerGlove

回答

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); 
相關問題