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

Jpeg images print two-tone, with no greyscaling to HP5 from Windows 95 on Novell

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs
    • 2d
    • x86
    • windows_95



      Name: rlT66838 Date: 04/10/2000


      C:\jdk1.3\bin>java -version
      java version "1.3.0rc2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
      Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)

      PROBLEM:

      Jpeg images do not print correctly. They print as two tone images with no grey
      scaling. (We are trying to print digital mug shots.) We are using an HP5
      Laserjet with a jet direct card on a Novell 4.11 network. This problem occurs
      on Windows 95 workstations, BUT NOT on Windows NT. The image prints fine on NT.

      This is the most simple source code I could come up with, but the problem occurs
      in any program we have tried. You will have to provide your own jpg image.

      When the program launches it will display the jpg image in the frame. Simply
      close the frame and the image will print. It does not display the printer
      dialog, but you could add that if you want.


      import java.awt.*;
      import java.awt.event.*;
      import java.awt.print.*;

      public class JpegPrinterBug extends Frame {

        Insets insets;
        Image im;
        int height;
        int width;

        // Obtain a printer job
        PrinterJob pjob = PrinterJob.getPrinterJob();
        PageFormat pf = pjob.defaultPage();
        Book bk = new Book();

        static public void main(String args[]) {

          JpegPrinterBug app = new JpegPrinterBug();
          app.show();
        }

        public JpegPrinterBug() {

          super("Image Test");
          im = Toolkit.getDefaultToolkit().getImage("dr.jpg");

          addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent event) {

              bk.append(new PaintImage(),pf);

              // Pass the book to the PrinterJob
              pjob.setPageable(bk);

              // Put up the dialog box
              if (pjob.printDialog()) {

                dispose();

                // Print the job if the user did not cancel
                try {
                  pjob.print();
                }
                catch (Exception e) {
                  e.printStackTrace();
                  System.out.println(e.toString());
                }
              }
              else {
                dispose();
              }
              System.exit(0);
            }
          });
        }

        public void addNotify() {

          super.addNotify(); // peer is created here
          insets = getInsets();

          do {
            height = im.getHeight(this);
            width = im.getWidth(this);
          } while (height == -1 || width == -1);

          setBounds(100, 100, width + insets.left, height + insets.top);
        }

        public void paint(Graphics g) {

          g.drawImage(im, insets.left, insets.top, this);
        }

        class PaintImage implements Printable {

          public int print(Graphics g, PageFormat pf, int pageIndex)
              throws PrinterException {

            //g.drawImage(im, 0, 0, this);

            if (pageIndex > 0) {
              return NO_SUCH_PAGE;
            }
            else {

              Graphics2D g2D = (Graphics2D) g;

              int leftBorder = (int)pf.getImageableX(),
                  topBorder = (int)pf.getImageableY(),
                  width = (int)pf.getImageableWidth(),
                  points = 12,
                  rowIncrement = 14,
                  lblIncrement = 20;

              int pictureLeft = (int)((leftBorder + width)*0.65);

              int currRow = 100,
                  col1 = 85,
                  col2 = 160;

              
              Font fnt;

              fnt = new Font("Helvetica-Bold",Font.BOLD, points);
              g2D.setFont(fnt);
              g2D.setColor(Color.blue);
              g2D.drawString("Name: ",col1,currRow);

              fnt = new Font("Helvetica-Bold",Font.PLAIN, points);
              g2D.setFont(fnt);
              g2D.setColor(Color.black);
              g2D.drawString("Reese, Daniel G.",col2,currRow);

              currRow += lblIncrement;

              fnt = new Font("Helvetica-Bold",Font.BOLD, points);
              g2D.setFont(fnt);
              g2D.setColor(Color.blue);
              g2D.drawString("Address: ",col1,currRow);

              fnt = new Font("Helvetica-Bold",Font.PLAIN, points);
              g2D.setFont(fnt);
              g2D.setColor(Color.black);
              g2D.drawString("45 N. Lake Ave.", col2,currRow);

              currRow += rowIncrement;

              g2D.drawString("Third Lake, IL 60046",col2,currRow);

              currRow += lblIncrement;

              fnt = new Font("Helvetica-Bold",Font.BOLD, points);
              g2D.setFont(fnt);
              g2D.setColor(Color.blue);
              g2D.drawString("Phones: ",col1,currRow);

              fnt = new Font("Helvetica-Bold",Font.PLAIN, points-2);
              g2D.setFont(fnt);
              g2D.setColor(Color.black);
              g2D.drawString("(847)223-8245", col2,currRow);

              currRow += rowIncrement;

              g2D.drawString("(847)494-3384",col2,currRow);

              double scaleX = 0.5;
              double scaleY = 0.5;
              double scale = Math.min(scaleX,scaleY);

              g2D.translate(pictureLeft,topBorder);
              g2D.scale(scale,scale);

              paint(g2D);
              return PAGE_EXISTS;
            }
          }
        }
      }
      (Review ID: 103492)
      ======================================================================

            prr Philip Race
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: