com.sap.ip.me.api.pios.printer
Class PrinterImage

java.lang.Object
  extended bycom.sap.ip.me.api.pios.printer.PrinterImage

public abstract class PrinterImage
extends java.lang.Object

The PrinterImage class represent an image, which can be used to render an image to the page printable area. Most printers support preloading of images to the printer's memory. The loaded image can be later referenced by name when needed for printing. Some printers may not support images altogether.

Example: Load image then print.
 

	Connector connector = Connector.getInstance();
	DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
	PrinterParameters parameters = new PrinterParameters(printers[0]);

	parameters.setPrinterMode(PrinterParameters.GRAPHIC_MODE);
	GraphicPrinter graphicPrinter = (GraphicPrinter)connector.open(parameters);

	File myImage = new File("logo32x32.bmp");

	if (myImage.exists()) {
		BufferedInputStream bfis = null;

		try {
			bfis  = new BufferedInputStream(new FileInputStream(myImage));
				
			int bufferSize = (int)myImage.length();
			byte[] imageBytes = new byte[bufferSize];
				
			int i = bfis.read(imageBytes, 0, bufferSize);
			if (i > 0) {
				PrinterImage image = graphicPrinter.createImage("logo", 
				PrinterImage.IMAGE_PCX, imageBytes);

				graphicPrinter.loadImage(image);
					
		 		graphicPrinter.drawImage(image.getName(), 100, 100, GraphicPrinter.NO_ROTATION);
			}
		}
		finally {
			if (bfis != null) bfis.close();				
		}
	}
		
	graphicPrinter.doPrint(1);
	graphicPrinter.close();

 
 

Since:
MI 2.5
Author:
Abaco
See Also:
PrinterConnection

Field Summary
static int IMAGE_BMP
          Constant to indicate a BMP image type.
static int IMAGE_PCX
          Constant to indicate a PCX image type.
 
Constructor Summary
PrinterImage(java.lang.String name, int type, byte[] image)
          Creates a new PrinterImage object using the specified name, type, and image.
 
Method Summary
 byte[] getBytes()
          Returns the image byte array.
abstract  Metrics getMetrics()
          Returns the image field metrics.
 java.lang.String getName()
          Returns the image name.
 int getType()
          Returns the image type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMAGE_BMP

public static final int IMAGE_BMP
Constant to indicate a BMP image type.

See Also:
Constant Field Values

IMAGE_PCX

public static final int IMAGE_PCX
Constant to indicate a PCX image type.

See Also:
Constant Field Values
Constructor Detail

PrinterImage

public PrinterImage(java.lang.String name,
                    int type,
                    byte[] image)
Creates a new PrinterImage object using the specified name, type, and image.

Parameters:
name - Name of the image on the printer.
type - Type of image, PCX or BMP.
image - Image bytes that will be sent to the printer.
Method Detail

getName

public java.lang.String getName()
Returns the image name.

Returns:
The image name.

getType

public int getType()
Returns the image type.

Returns:
The image type.

getBytes

public byte[] getBytes()
Returns the image byte array. If there are no bytes an empty array is returned.

Returns:
The byte array that represents the image.

getMetrics

public abstract Metrics getMetrics()
                            throws PrinterException
Returns the image field metrics.

Returns:
The Metrics object with the image dimension.
Throws:
PrinterException - thrown if unable to obtain image field metrics


Copyright © 2005 SAP AG. All Rights Reserved.