Solved! It seems the translation, although only a few pixels, was
pushing part of the LANDSCAPE image off the printed page and so none
showed when I viewed the out.ps file in ggv. The class below shows my
working code.
Thanks for your help.
public class ImagePrinter implements Printable
{
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;
}
// Make sure not to print in the paper's margin.
Interpolation interp = Interpolation.getInstance(
Interpolation.INTERP_NEAREST );
ParameterBlock pb = new ParameterBlock();
if ( pf.getOrientation() == pf.LANDSCAPE )
{
RenderedOp image = myFrame.getRenderedOpImage();
pb.addSource( image );
pb.add( -(float)pf.getImageableX() );
pb.add( 0.0F );
}
else
{
pb.addSource( myFrame.getRenderedOpImage() );
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;
}
}
On Wed, 2001-09-26 at 17:18, Phil Race wrote:
> If the orientation is landscape the printing implementation is going
> to apply a rotation for you , and you should notice this as the width and
> height of the page format being swapped.
> So you don't need to do the rotate yourself although you will want to
> be aware of the different imageable area.
>
> I guess one of these operations lost your image but its hard to say which
> (although I don't remember any landscape printing problems on linux)
>
> I believe the JAI transpose operator will do the rotation around the centre
> of the image, so I am not sure that you've simply rotated your image
> off the page, although that's worth checking out and verifying.
>
> But given that you don't need to apply *both* of these rotations you
> could try just one at a time and see which one causes the problem (and
> you may be able to just do without the one that is the problem).
>
> -phil.
>
>
--
------------------------------------------------------------------------
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".