Show TOC Start of Content Area

This graphic is explained in the accompanying text Rotate and Print an Image  Locate the document in its SAP Library structure

In this example, the printer is in Graphic mode and prints a rotated image (using test.bmp in the c:\Temp\ directory). The program performs the following steps:

...

       1.      Opens the image file.

       2.      Opens the connection to the printer.

       3.      Loads the image to the printer's memory.

       4.      Obtains the image height.

       5.      Prints the drawn image with a 90-degree rotation.

       6.      Closes the connection to the printer.

 

package test;

 

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import com.sap.ip.me.api.pios.connection.*;

import com.sap.ip.me.api.pios.printer.*;

 

public class RotateImage {

 

   public static void main(String[] args) {

      GraphicPrinter gP = null;

      PrinterImage image = null;

      float x = 0, y = 15;

     

      try {

        

         Connector conn = Connector.getInstance();

         DriverInfo[] driverInfo = conn.listDrivers(ConnectionType.PRINTER);

         PrinterParameters params = new PrinterParameters(driverInfo[0]);

         params.setPrinterMode(PrinterParameters.GRAPHIC_MODE);

 

         try {

            //-------------------(1)--------------------

            File testImage = new File("C:\\TEMP\\test.bmp");

            if (testImage.exists()) {

               BufferedInputStream bfis = null;

           

               try {

                  bfis = new BufferedInputStream(new FileInputStream(testImage));

              

                  int bufferSize = (int)testImage.length();

                  byte[] imageBytes = new byte[bufferSize];

              

                  int i = bfis.read(imageBytes, 0, bufferSize);

 

                  //-------------(2)--------------------

                  gP = (GraphicPrinter) conn.open(params);

                 

                  if (i > 0) {

                     image = gP.createImage("test", PrinterImage.IMAGE_BMP, imageBytes);

 

                     //----------(3)--------------------

                     gP.loadImage(image);

                  }

               }

               finally {

                  if (bfis != null) bfis.close();

               }

            }

         }

         catch (Throwable tFile) {

            tFile.printStackTrace();        

         }

 

         //----------------------(4)--------------------

         x = image.getMetrics().getHeight() + 10;

 

         //----------------------(5)--------------------

         gP.drawImage(image.getName(), x, y, GraphicPrinter.ROTATE_90_DEGREES);

         gP.doPrint(1);

 

      }

      catch (Throwable e){

         e.printStackTrace();

      } finally {

         //----------------------(6)--------------------

         try {

            gP.close();

         } catch (Exception ex) {}

   }

      return;    

   }

}

 

End of Content Area