I have a program that prints an image fine when I print in portrait mode
but come out blank (all white, all 0xFFFF) in landscape. I am using
transpose to rotate the image for landscape. The code is below. I'm
using JDK 1.3.1 on RedHat 6.2. Any ideas? Isn't "transpose" how I want
to flip it?
public class ImagePrinter implements Printable
{
RenderedOp image;
RenderedOp rendered_image;
JAIFrame myFrame;
/** Creates new ImagePrinter */
public ImagePrinter (
JAIFrame frame )
{
this.myFrame = frame;
}
/**
Displays the page setup and print dialogs and prints the
image.
*/
public void doPrinting()
{
PrinterJob job = PrinterJob.getPrinterJob();
Book book = new Book();
PageFormat defaultPageFmt = job.defaultPage();
PageFormat pf = job.pageDialog( defaultPageFmt );
// Cancel was pressed.
if ( pf.equals( defaultPageFmt ) )
{
return;
}
book.append( this, pf );
job.setPageable( book );
if ( !job.printDialog() )
{
return;
}
if ( pf.getOrientation() == pf.LANDSCAPE )
{
// Rotate the image.
ParameterBlock pbTrans = new ParameterBlock();
pbTrans.addSource( myFrame.getRenderedOpImage() );
pbTrans.add( TransposeDescriptor.ROTATE_270 );
image = JAI.create( "transpose", pbTrans, null );
}
else
{
image = myFrame.getRenderedOpImage();
}
// Make sure not to print in the margin.
Interpolation interp = Interpolation.getInstance(
Interpolation.INTERP_NEAREST );
ParameterBlock pb = new ParameterBlock();
pb.addSource( image );
pb.add( (float)pf.getImageableX() );
pb.add( (float)pf.getImageableY() );
pb.add( interp );
rendered_image = (RenderedOp)JAI.create( "translate", pb, null
);
try
{
job.print();
}
catch ( PrinterException e )
{
e.printStackTrace();
}
}
public int print (
Graphics g,
PageFormat pf,
int pi )
throws PrinterException
{
if ( pi != 0 )
return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.drawRenderedImage( rendered_image, new AffineTransform() );
System.gc();
return PAGE_EXISTS;
}
}
--
-------------------------------------------------------------------------
Thad Humphries "...no religious test shall ever be
required
Web Development Manager as a qualification to any office or public
Phone: 540/675-3015, x225 trust under the United States." -Article
VI
===========================================================================
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".