Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8040636

Printing graphics in high resolution with transparency fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 7u25, 8, 9
    • client-libs
    • 2d
    • windows_7

      FULL PRODUCT VERSION :
      C:\Users\Christian>java -version
      java version "1.7.0_25"
      Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
      Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)



      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 32

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Eclipse Juno

      A DESCRIPTION OF THE PROBLEM :
      When printing drawings in hight resolution, with transparency, it seems that the area printed is in fact a part of the sheet, not the picture programmed (sorry for my english).

      If we set another flag, which disables transparency, then it works fine.

      See source code attached whith comments.

      REGRESSION. Last worked in version 7u25

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run provided code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Same as 72 dpi printing, but in hight resolution

      ACTUAL -
      Drawing fails

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no error message

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Button;
      import java.awt.Color;
      import java.awt.FlowLayout;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.geom.AffineTransform;
      import java.awt.image.BufferedImage;
      import java.awt.print.PageFormat;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PrinterJob;

      import javax.swing.JFrame;

      public class printer extends JFrame implements ActionListener{
      private static final long serialVersionUID = 1L;
      Button bPrint72dpi = new Button ("Print in 72 dpi");
      Button bPrintPrinterResolution = new Button ("Print in printer resolution");

      public printer() {
      super();

      setSize(300, 100);
      setLayout(new FlowLayout());

      add(bPrint72dpi);
      bPrint72dpi.addActionListener( this);

      add(bPrintPrinterResolution);
      bPrintPrinterResolution.addActionListener( this);

      setLocationRelativeTo(null);
      setVisible(true);
      }

      public static void main(String[] args) {
      new printer();
      }

      @Override
      public void actionPerformed(ActionEvent e) {
      if (e.getSource() == bPrint72dpi) {
      print72dpi();
      } else {
      printfullresolution();
      }
      }

      private void print72dpi() {

      PrinterJob job = PrinterJob.getPrinterJob();
      job.setPrintable (new Printable() {

      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {

      if ( pageIndex > 0 ) {
      return(NO_SUCH_PAGE);
      } else {
      Graphics2D g2 = (Graphics2D) g;
      g2.translate( pageFormat.getImageableX(), pageFormat.getImageableY());

      printNow( g2);

      return(PAGE_EXISTS);
      }
      }
      });

      if ( job.printDialog() )
      try {
      job.print();
      }
      catch(PrinterException pe) {
      System.out.println("Error printing...");
      }

      }
      private void printfullresolution() {
      PrinterJob job = PrinterJob.getPrinterJob();
      job.setPrintable (new Printable() {

      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {

      if ( pageIndex > 0 ) {
      return(NO_SUCH_PAGE);
      } else {
      Graphics2D g2 = (Graphics2D)g;
      g2.setTransform(new AffineTransform());//full resolution when printing

      g2.setFont( new Font("Arial", Font.PLAIN, 50 ));

      printNow( g2);

      return(PAGE_EXISTS);
      }
      }
      });

      if ( job.printDialog() )
      try {
      job.print();
      }
      catch(PrinterException pe) {
      System.out.println("Erreur d'impression");
      }
      }

      private void printNow ( Graphics2D g2) {

      g2.drawString( "something to print", 50, 50);

      BufferedImage i = new BufferedImage( 100, 100, BufferedImage.TYPE_INT_ARGB );//black square
      // runs fine TYPE_INT_RGB instead of TYPE_INT_ARGB
      //BufferedImage i = new BufferedImage( 100, 100, BufferedImage.TYPE_INT_RGB );
      Graphics gi = i.getGraphics();
      gi.setColor( Color.blue);
      gi.drawRect(0, 0, i.getWidth()-1, i.getHeight()-1);//to have something to look at
      gi.dispose();

      g2.drawImage( i, 100, 100, null);
      i=null;

      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no Workaround found if we want to keep transparency.

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: