0

I have converted the rich text to image and saved as a blob to db. Blob is created fine from local server (WINDOWS) but when deployed to application server (LINUX). The image format(font, sharpness) got changed. I am not sure what I have to do. please shed some light. Here is code which I used.

        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);

Which image format is good for text content?

Thanks in advance.

Image from Local server (WINDOWS)

enter image description here

Image from Linux server (application server) (Linux)

enter image description here

Harish
  • 425
  • 3
  • 7
  • 19
  • You specify two image formats, JPEG for writing to (a Windows-specific) file, and GIF for writing to an in-memory stream. What do you mean by *"The image format(font, sharpness) got changed"*? It may be easier to understand/visualize if you post a side by side comparison with Windows and Linux output. Most likely the font/antialias changed, because you use a Swing component (`JEditorPane`), which have different "look and feel" for Windows and Linux (Gnome/KDE/whatever). You may work around that by a cross platform look and feel. – Harald K Jan 13 '17 at 15:32
  • The images I copied here are both .png type one from the local and one from server and used BufferedImage.TYPE_INT_RGB.. Let me edit my code. – Harish Jan 13 '17 at 20:02
  • What was your text with font and sharpness stored in before, was it also displayed in a `JEditorPane`? – NESPowerGlove Jan 13 '17 at 21:02
  • Yes In JEditorPane - "font-family: Arial, Verdana; font-size: 13.3333px. Look at the images I copied. – Harish Jan 13 '17 at 21:22
  • Do you have Arial on both platforms? What Swing look and feels do you use (for each platform)? What Java2D rendering pipelines do you use? You probably need to use the same on both platforms if you expect equal results. – Harald K Jan 16 '17 at 08:12
  • I have change the font to verdana and to other fonts but no luck. I am not using any swing components for look and feel I am storing the image as a blob and retrieving the Blob in a PDF using BIPublisher. – Harish Jan 16 '17 at 15:11

1 Answers1

0

I have also used this code and still have the same problem.

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);
Harish
  • 425
  • 3
  • 7
  • 19