Hi Kate-
Does it make any difference if the [width,height]
are exactly the same as the panel size?
This is not a JAI problem and probably Java2D-interest
will provide a satisfactory solution.
Good luck,
John
----
From: "Wintjen, Kate" <[EMAIL PROTECTED]>
Subject: Drawn image rendering quality
Content-Type: text/plain; charset="iso-8859-1"
I'm using the following code to render an image I have drawn in a custom
panel:
String filename = "myfile.png";
BufferedImage buff = (BufferedImage)createImage(width, height);
Graphics2D g2d = buff.createGraphics();
panel.paintComponent(g2d);
JAI.create("filestore", buff, filename, "PNG", null);
This works, but there's something we're trying to fix. There's some text in
the drawing, and it's not exactly coming out the way we'd like, although it
is probably coming out as one would or should expect.
If we turn on anti-aliasing using RenderingHints, it looks great on the
screen, even after opening the file for viewing. However, the text prints
out fuzzy. If we make sure anti-aliasing is off with RenderingHints, it
doesn't look as good on the screen, and printing makes the text very jagged
and pixelated.
To print, we're using this class (found off the internet):
public class PrintUtilities implements Printable {
private Component componentToPrint;
public static void printComonent(Component c) { }
public static void printComponent(Component c, Rectangle r) {
new PrintUtilities(c).print(r, orientation);
}
public void print(Rectangle r) {
PrinterJob printJob = PrinterJob.getPrinterJob();
PageFormat pformat = printJob.defaultPage();
Paper paper = new Paper();
pformat.setOrientation(PageFormat.PORTRAIT);
paper.setImageableArea(r.x, r.y, r.width, r.height);
pformat.setPaper(paper);
printJob.setPrintable(this, pformat);
if (printJob.printDialog()) {
try {
printJob.print();
}
catch (PrinterException e) {
System.out.println("Error: " + e);
}
}
}
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) return(NO_SUCH_PAGE);
else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormage.getImageableX(),
pageFormat.getImageableY());
disableDoubleBuffering(componentToPrint);
componentToPrint.paint(g2d);
enableDoubleBuffering(componentToPrint);
return(PAGE_EXISTS);
}
}
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}
Then, in the class we're printing the panel from, we call:
PrintUtilities.printComponent(panel, rect);
The quality of the text when printing is absolutely perfect: it's clear and
smooth with no fuzziness or pixelation, regardless of whether anti-aliasing
was on or off. This is exactly what we'd like to achieve when saving our
images, is that wonderful text quality.
Is there any way of doing this? I'm asking here because it might be
possible with the JAI package, even though there may be other solutions.
We've already tried looking at the various objects PrintUtilities uses in
order to see if there was a way to capture the output (in bytes I suppose)
being sent to the printer, but so far that's a no-go. So, I'm hoping
there's something in the JAI package that will do what we'd really like.
Thanks for reading my long-winded post!
Kate Wintjen
Kate Wintjen
:-) <[EMAIL PROTECTED]>
* 314-232-6086
* S306-4060
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".