From: <doc...@us...> - 2007-06-15 01:37:32
|
Revision: 88 http://openpcl.svn.sourceforge.net/openpcl/?rev=88&view=rev Author: documentsystems Date: 2007-06-14 18:32:36 -0700 (Thu, 14 Jun 2007) Log Message: ----------- Howard Hoagland. Converted the full color BufferedImage bitmap of the printed image to a 2 color black and white only BufferedImage before drawing on the Graphics2D in Java Printing. This makes the printing go faster because the print image in the print queue is 1.28MB per print page instead of 10MB per print page. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-06-14 22:46:28 UTC (rev 87) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-06-15 01:32:36 UTC (rev 88) @@ -1,6 +1,7 @@ package com.openpcl.viewer.printing; import java.awt.Color; +import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; @@ -17,6 +18,7 @@ import javax.swing.JOptionPane; import javax.swing.JProgressBar; +import com.openpcl.pclrenderimage.render.PriPageSettings; import com.openpcl.viewer.panels.PosView; import com.openpcl.viewer.tree.PosTreeNode; @@ -24,19 +26,28 @@ private static final long serialVersionUID = 1L; private PosView mPosView = null; private BufferedImage mPrintThisBufferedImage = null; + private BufferedImage mBufferedImageToPrintOn = null; + private Graphics2D mGraphics2DToPrintOn = null; + private Frame mParentFrame = null; + private PosTreeNode mPrintThisTreeNode = null; private AffineTransform mOrigAffineTransform = null; private AffineTransform mScaleAffineTransform = null; private ArrayList<PosTreeNode> mPagesToPrintArrayList = null; private PosPrintSetupDialogChoices mPosPrintSetupDialogChoices = null; private JProgressBar mPrintingProgressBar = null; - private static final String mProgressBarBaseString = "Generating page: "; + private static final String sProgressBarBaseString = "Generating page: "; + private static final String sCantAllocate = "Can't allocate memory for temporary image used for printing."; private double mPrintScale = 72.0d / 300.0d; // making width and height using 72 / 300 scale public PosPrintBufferedImage(PosView pPosView) { super(); mPosView = pPosView; + mParentFrame = mPosView.getOpenPCLViewer().getAppFrame(); mScaleAffineTransform = AffineTransform.getScaleInstance(mPrintScale, mPrintScale); + mBufferedImageToPrintOn = createNewBufferedImageToPrintOn(); + // Graphics2D for printing (is 2 color black and white with no rendering hints like anti-aliasing + if (mBufferedImageToPrintOn != null) { mGraphics2DToPrintOn = mBufferedImageToPrintOn.createGraphics(); } } public void setPagesToPrint(ArrayList<PosTreeNode> pPagesToPrintArrayList) { @@ -90,9 +101,12 @@ // methods specified in the interface IPluginHooksOpenPCL mPrintThisBufferedImage = mPosView.getOpenPCLViewer().renderImageForPrintingFromTreeNode(mPrintThisTreeNode); - // Draw the screen image on the printer Graphics2D using the scale down transform - g2D.drawImage(mPrintThisBufferedImage, 0, 0, Color.WHITE, this); + // Convert to 2 color black and white so the print image file sent to the printer is 1.3MB per print page instead of 10MB + mGraphics2DToPrintOn.drawImage(mPrintThisBufferedImage, 0, 0, this); + // Draw the image on the printer Graphics2D using the scale down transform + g2D.drawImage(mBufferedImageToPrintOn, 0, 0, this); + // Revert back to the passed in AffineTransform because the JDK doc for printing says put back the // passed in Graphics object's settings back if you modified it in this print() interface call g2D.transform(mOrigAffineTransform); @@ -100,7 +114,7 @@ // Update the progress bar at each page if (mPrintingProgressBar != null) { mPrintingProgressBar.setValue(pPageNumber + 1); - mPrintingProgressBar.setString(mProgressBarBaseString + (pPageNumber + 1) + " of " + mPagesToPrintArrayList.size()); + mPrintingProgressBar.setString(sProgressBarBaseString + (pPageNumber + 1) + " of " + mPagesToPrintArrayList.size()); } return Printable.PAGE_EXISTS; @@ -138,4 +152,43 @@ } } + /** + * Create a new BufferredImage all ready to print on + * @return BufferedImage + */ + protected BufferedImage createNewBufferedImageToPrintOn() { + BufferedImage tToPrintOnBufferedImage = null; + try { + tToPrintOnBufferedImage = new BufferedImage( + PriPageSettings.sNumPixels85Inches, // make the BufferedImage be 8.5 inches by 14 inches + PriPageSettings.sNumPixels14Inches, + BufferedImage.TYPE_BYTE_BINARY); // 2 color only image is black and white (not full color) for printing not on screen + } catch (OutOfMemoryError e1) { + tToPrintOnBufferedImage = null; + JOptionPane.showMessageDialog(mParentFrame, "Out of heap space memory. " + sCantAllocate , "Heap space memory", + JOptionPane.ERROR_MESSAGE); + + } catch (Error e2) { + tToPrintOnBufferedImage = null; + JOptionPane.showMessageDialog(mParentFrame, "Error. " + sCantAllocate , "Error", + JOptionPane.ERROR_MESSAGE); + + } catch (Exception e3) { + tToPrintOnBufferedImage = null; + JOptionPane.showMessageDialog(mParentFrame, "Exception. " + sCantAllocate , "Exception", + JOptionPane.ERROR_MESSAGE); + } + return tToPrintOnBufferedImage; + } + + /** Blank out the BufferedImage on the screen of the current selected view. */ + public void blankOutBufferedImageToPrintOn() { + if (mBufferedImageToPrintOn != null && mGraphics2DToPrintOn != null) { + mGraphics2DToPrintOn.setPaint(Color.WHITE); + // The blank out is done by drawing a white rectangle on the whole image + mGraphics2DToPrintOn.fillRect(0, 0, mBufferedImageToPrintOn.getWidth(), mBufferedImageToPrintOn.getHeight()); + // Make the initial color for drawing text and rectangles and pixels be in black. Can be set to another color like blue later + mGraphics2DToPrintOn.setPaint(Color.BLACK); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |