Hello everyone.
This is my first post to this list.
Question 1.
I tried the following code "TiffPrintTest.java" to print
bilevel(Black and White) TIFF files. The target TIFF file
is a G4 400dpi document (BLACK strings on WHITE background).
What I got on the printer is BLACK strings on a GRAY
background which looks like filled with small
black-and-white patterns.
I am quite a beginer and have no idea why background
is GRAY.
Does anyone know the reason and how to get the WHITE
background ?
Question 2
I tried another code "PrintableTest.java" and got WHITE
background. But I could not find out how to set
PRINTER-RESOLUTION to PrinterJob. (I could set
PRINTER-RESOLUTION to PrintJob using PageAttributes's
setPrinterResolution() method)
Still more, to print G4 TIFF , memory consumption is
unacceptably huge.
Does anyone know how to set PRINTER-RESOLUTION to
PrinterJob ?
How can I print G4 TIFF with small memory ?
Any suggestion would be appreciated.
Thanks in advance.
----------- TiffPrintTest.java -----------------------------------
// JDK1.3 + JAI1.0.1
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.media.jai.*;
public class TiffPrintTest extends Frame
implements ActionListener
{
BufferedImage bufferedImg = null;
static final int FRM_WIDTH = 300;
static final int FRM_HEIGHT = 300;
TiffPrintTest(String file) {
bufferedImg = getTIFF( file );
Panel p = new Panel();
Button b1 = new Button("print");
b1.addActionListener(this);
p.add(b1); add(p,BorderLayout.NORTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0); }
});
}
private BufferedImage getTIFF (String filename) {
PlanarImage image = JAI.create("fileload", filename);
byte[] array = new byte[] {(byte)0xff, (byte)0};
ColorModel cm = new IndexColorModel(1, 2, array, array, array);
WritableRaster wr =
Raster.createPackedRaster(image.getData().getDataBuffer(),
image.getWidth(), image.getHeight(),
1, new Point(0, 0));
BufferedImage bufImage = new BufferedImage(cm , wr, false, null);
return bufImage;
}
public void paint(Graphics g) {
g.drawImage( (Image)bufferedImg, 0, 0,FRM_WIDTH, FRM_HEIGHT-30,
this);
}
public void actionPerformed(ActionEvent event) {
if( event.getActionCommand() == "print") printTiff();
}
public void printTiff() {
PageAttributes page_attr = new PageAttributes();
page_attr.setPrinterResolution( 400 ); /* 400 dpi */
PrintJob pjob = getToolkit().getPrintJob(this,"Tiff Print",
null,page_attr);
Graphics g = pjob.getGraphics();
g.drawImage((Image)bufferedImg, 0, 0, this) ;
g.dispose();
pjob.end();
}
public static void main(String argv[]) {
if(argv.length < 1) {
System.out.println("Usage: java TiffPrintTest <TIFF-file-name>");
System.exit(1);
}
Frame f = new TiffPrintTest(argv[0]);
f.setTitle("TIFF PRINT TEST : " + argv[0]);
f.setSize(FRM_WIDTH, FRM_HEIGHT);
f.show();
}
}
----------- PrintableTest.java -----------------------------------
// JDK1.3 + JAI1.0.1
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.print.*;
import javax.media.jai.*;
public class PrintableTest extends Frame
implements ActionListener
{
BufferedImage bufferedImg = null;
static final int FRM_WIDTH = 300;
static final int FRM_HEIGHT = 300;
PrintableTest(String file) {
bufferedImg = getTIFF( file );
Panel p = new Panel();
Button b1 = new Button("print");
b1.addActionListener(this); p.add(b1);
add(p,BorderLayout.NORTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0); }
});
}
private BufferedImage getTIFF (String filename) {
PlanarImage image = JAI.create("fileload", filename);
byte[] array = new byte[] {(byte)0xff, (byte)0};
ColorModel cm = new IndexColorModel(1, 2, array, array, array);
WritableRaster wr =
Raster.createPackedRaster(image.getData().getDataBuffer(),
image.getWidth(), image.getHeight(),
1, new Point(0, 0));
BufferedImage bufImage = new BufferedImage(cm , wr, false, null);
return bufImage;
}
public void paint(Graphics g) {
g.drawImage( (Image)bufferedImg, 0, 0,
FRM_WIDTH, FRM_HEIGHT-30, this);
}
public void actionPerformed(ActionEvent event) {
if( event.getActionCommand() == "print") printTiff();
}
public void printTiff() {
MyPagePainter painter = new MyPagePainter();
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat fmt = pjob.pageDialog(pjob.defaultPage());
pjob.setPrintable(painter,fmt);
if( pjob.printDialog() ) {
try { pjob.print(); }
catch(Exception ex) { System.err.println(ex); }
}
else {
System.err.println("PrintJob canceled");
}
}
public static void main(String argv[]) {
if(argv.length < 1) {
System.out.println("Usage: java PrintableTest <TIFF-file-name>");
System.exit(1);
}
Frame f = new PrintableTest(argv[0]);
f.setTitle("TIFF PRINT TEST : " + argv[0]);
f.setSize(FRM_WIDTH, FRM_HEIGHT);
f.show();
}
class MyPagePainter implements Printable
{
public int print(Graphics g, PageFormat fmt, int pageIndex) {
Graphics2D g2d = (Graphics2D)g;
if( pageIndex > 1 )
return Printable.NO_SUCH_PAGE;
else {
g.drawImage((Image)bufferedImg, 0, 0, null) ;
return Printable.PAGE_EXISTS;
}
}
}
}
--
Best regards,
Taku Honda TOSHIBA CAE Inc. Kawasaki, Japan
tel:044-548-4032 fax:044-548-4069
E_mail:[EMAIL PROTECTED]
===========================================================================
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".
