Hmm, I'm using an old Canon LBP-430 printer. Maybe there's a difference in the printer drivers. Eventually I'll be using brand new large format Epson and HP printers for my product.

On the other hand, you're scaling larger, while I'm scaling a very large image (4865 x 5972) to letter size paper with a 1 inch margin (468 x 468) for a scale factor of 0.108. I'm not using rending hints as I'm scaling down. If it's not too much trouble, could you try scaling down with your printer and see if the a/b results are the same?

You have proved that (a) and (b) are very different in scaling up. Good work! I'm not sure if it works going the other way.

Normally I would have thought the Java printing support and/or the printing drivers would have scaled the output size accordingly too. Since the scale is 10% smaller, and it the area we're talking about, the output size should be 100 times smaller. For an 80 MB image, that should be 800 KB. If I do the following

BufferedImage original = ImageIO.read(file.png);
BufferedImage printable =
    new BufferedImage(
        (int)(scale * original.getWidth(),
        (int)(scale * original.getHeight(),
        BufferedImage.TYPE_3BYTE_BGR);

AffineTransform transform = new AffineTransform();
transform.scale(scale, scale);

Graphics2D g = original.createGraphics();
g.drawImage(original, transform, null);


then print printable, the output file is only 900 KB, or about what I would expect. Unfortunately, the image fidelity is off because the original BufferedImage is loaded from a PNG file and is TYPE_CUSTOM with a "ColorModel: #pixelBits = 24 numComponents = 3 color space = [EMAIL PROTECTED] transparency = 1 has alpha = false isAlphaPre = false" As far as I know there is no way to clone a BufferedImage with different dimensions, but the same type and colour model. I tried creating BufferedImage of TYPE_CUSTOM, but the Java runtime complained. As an aside, the first time I tried this I used TYPE_INT_BGR, and the printed image came out very light and dithered. TYPE_3BYTE_BGR is suppose to be sRGB (I think).

More importantly, why do I need to create a second BufferedImage, why can't Graphics2D and/or the printer driver do the right thing to begin with? The mysteries of Java printing...

Thanks for providing me with the details of your experiment. When I have to scale up I'll know which method to use.

By the way, when would someone choose Bicubic interpolation?

Cheers, Eric

Gunter Zeilinger wrote:
Just tested under Java 1.4.1_01/Linux 2.4.18-686 -> cups 1.1.14 -> hp psc 750 with 300x300dpi:

a)

public int print(Graphics g, PageFormat pf, int pageIndex) {
 if (pageIndex == 0) {
  BufferedImage bi = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
  bi.setRGB(0, 0, 0x000000);
  bi.setRGB(0, 1, 0xffffff);
  bi.setRGB(1, 0, 0xffffff);
  bi.setRGB(1, 1, 0x000000);

  Graphics2D g2d = (Graphics2D) g;
  g2d.translate(pf.getImageableX(), pf.getImageableY());
  g2d.scale(200, 200);
  g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
     RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2d.drawImage(bi, null, null);
  return Printable.PAGE_EXISTS;
 } else {
  return Printable.NO_SUCH_PAGE;
}

=> PrintJob size: 3k
RenderingHints.VALUE_INTERPOLATION_BILINEAR ignored!

b)
public int print(Graphics g, PageFormat pf, int pageIndex) {
 if (pageIndex == 0) {
  BufferedImage bi = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
  bi.setRGB(0, 0, 0x000000);
  bi.setRGB(0, 1, 0xffffff);
  bi.setRGB(1, 0, 0xffffff);
  bi.setRGB(1, 1, 0x000000);

  Graphics2D g2d = (Graphics2D) g;
  g2d.translate(pf.getImageableX(), pf.getImageableY());
  AffineTransform af = g2d.getTransform();
  g2d.scale(1. / af.getScaleX(), 1. / af.getScaleY());
  af.scale(200, 200);
  AffineTransformOp op = new AffineTransformOp(af,
      AffineTransformOp.TYPE_BILINEAR);

  BufferedImage dest = op.filter(bi, null);
  g2d.drawImage(dest, null, null);
  return Printable.PAGE_EXISTS;
 } else {
  return Printable.NO_SUCH_PAGE;
}

=> PrintJob size:  426k
bilinear Interpolation!

===========================================================================
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".
  

Reply via email to