Creating and printing a BufferedImage with Robot class

I use class robot to create a bufferedImage of a screenCapture.
But all it keeps printing is a black box.
What am I missing here?
Dimension dim = mainPanel.getSize();
Robot robot = null;
try{ 
       robot = new Robot();
    final BufferedImage bufferedImage = robot.createScreenCapture(new Rectangle
                                           (mainPanel.getLocationOnScreen().x,
                                            mainPanel.getLocationOnScreen().y,
                                            dim.width,
                                            dim.height));
    catch( Exception e ){}     
        PrintUtilities.printImage(bufferedImage);Printing code
public class PrintUtilities implements Printable{
          private BufferedImage bufferedImage;
  public static void printImage(BufferedImage c) { 
          new PrintUtilities(c).print();
  public PrintUtilities( BufferedImage bufferedImage ){
         this.bufferedImage = bufferedImage;
  public void print(){
         PrinterJob printJob = PrinterJob.getPrinterJob();
         printJob.setPrintable(this);
           if (printJob.printDialog())
            try {
                  printJob.print();
                  System.out.println("calling printjob " );
            catch(PrinterException pe)
                   System.out.println("Error printing: " + pe);
public int print(Graphics g, PageFormat pf, int pageIndex){
             Graphics2D g2d = (Graphics2D)g;
             int imageWidth = bufferedImage.getWidth(); //width in pixels
             int imageHeight = bufferedImage.getHeight(); //height in pixels
             g2d.drawImage( bufferedImage, 0, 0, (int)pageWidth, (int)pageHeight, null );
             return Printable.PAGE_EXISTS;
          }

Ok, day 4 of working on this. Dukes are still up for grabs.
I created a small pop up frame in the print method of the print Utilities class to display the buffered image, worked fine. So the problem seems to be in the drawImage()
Someone has got to have a clue as to why this just printing a black box
The call to the print class:
PrintUtilities.printImage(bufferedImage);
The entire print class:
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
import java.awt.image.BufferedImage;
  public class PrintUtilities implements Printable{
          private BufferedImage bufferedImage;
  public static void printImage(BufferedImage c) { 
          new PrintUtilities(c).print();
  public PrintUtilities( BufferedImage bufferedImage ){
         this.bufferedImage = bufferedImage;
  public void print(){
         PrinterJob printJob = PrinterJob.getPrinterJob();
         printJob.setPrintable(this);
           if (printJob.printDialog())
            try {
                  printJob.print();
            catch(PrinterException pe)
                   System.out.println("Error printing: " + pe);
  public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
     Graphics2D g2d = (Graphics2D)g;
     int panelWidth    = bufferedImage.getWidth(); //width in pixels
     int panelHeight   = bufferedImage.getHeight(); //height in pixels
     double pageHeight = pf.getImageableHeight(); //height of printer page
     double pageWidth  = pf.getImageableWidth(); //width of printer page
     if( pageIndex >= 1 ){
          return Printable.NO_SUCH_PAGE;
            // shift Graphic to line up with beginning of print-imageable region
      g2d.translate(pf.getImageableX(), pf.getImageableY());
      g2d.drawImage( bufferedImage, 10, 10, (int)pageWidth, (int)pageHeight, null );
      return Printable.PAGE_EXISTS;
}// close print class.

Similar Messages

  • How to create and print contact sheet using photoshop elements 10?

    how to create and print contact sheet with photoshop 10?

    Which operating system are you using?
    On a windows system you can use the Organizer
    http://www.dummies.com/how-to/content/how-to-print-contact-sheets-in-photoshop-elements-.h tml
    On a Mac, File>Contact Sheet II within the pse 10 editor

  • Resizing and Printing a bufferedImage.

    I have a bufferedImage , and I was wondering if somebody could supply me with a method to resize it to the paper size and print it out with out asking the user anything. Except are you sure you want to print? This would be of great help!

    Use AffineTransformOp.
    Here is my code
    //create an affinetransform (methods to set scale and rotation - I'm setting values directly)
    AffineTransform image_at=new AffineTransform(Trm[0][0],Trm[1][0],Trm[0][1],(Trm[1][1]),0,0);
    //make an imageOp
    AffineTransformOp flip= new AffineTransformOp(image_at,hints);
    //apply the opt to current image and put result in temp_image
    temp_image=flip.filter(current_image,null);
    MArk

  • Hello, I would like to create and print a contact sheet in Photoshop elements 13. I have managed to do that but I need desperately to be able to place a title on the contact sheet. Also, each photograph has as name and I need these names to show up on the

    Hello, I would like to create and print a contact sheet in Photoshop elements 13. I have managed to do that but I need desperately to be able to place a title on the contact sheet. Also, each photograph has as name and I need these names to show up on the contact sheet when I print them out. If this is not possible I will just return my product. I have an old old version of Photoshop that will do just that but with this new elements I cannot find it.

    markc
    What computer operating system is your Premiere Elements 13/13.1 running on?
    Assuming Windows 7, 8, or 8.1 64 bit, open the Elements Organizer 13/13.1 and select your media
    for the Contact Sheet.
    Go to File Menu/Print and set up the Print Dialog for Contact Sheet.
    If you used Edit Menu/Add Caption beforehand, I can see how you can get
    Date
    Caption
    Filename
    under the Print dialog's "4" and even a page number if you have more than 1 page. But, I am not seeing
    where you are going to get a title for each of the contact sheets.
    Any questions or need clarification, please do not hesitate to ask.
    You can get into the Elements Organizer 13/13.1 from the Welcome Screen or by clicking on the Organizer Tab
    at the bottom of the Expert workspace in the Premiere Elements 13/13.1 Editor.
    Please let us know if we have targeted your quesiton..
    Thank you.
    ATR

  • How to Create and Remove CMP Entity with Toplink in same transaction??

    Hi, i have a problem to create and delete cmp intances with toplink.
    I create a entity bean and remove the same entity bean in the same transaction.
    ie. my method have this code:
    bean a = homeBean.create(pk);
    a.remove();
    bean a = homeBean.create(pk);
    this code throws a javax.ejb.DuplicateKeyException
    Toplink not remove CMP, execute the two calls of create first.
    What configure toplink to support this case ??
    Is this possible ??
    I Can't controling the transaction manualy i'm using CMP entity beans with CMT.
    tanks.
    Message was edited by:
    Carlos Lacerda

    BM,
    If you want to import the utils package into your code, then the location of the utils package has to be in your CLASSPATH. JDeveloper uses libraries to define a project's CLASSPATH.
    I'm not sure exactly what's going on here, but you might want to read the information about packages and class libraries in the online documentation. It's under:
    User Guides
    -> Working with JDeveloper
    -> Packages and Class Libraries
    Blaise

  • Hello, I would like to create and print a contact sheet in Photoshop Premier Elements 13. I have managed to do that but I need desperately to be able to place a title on the contact sheet. Also, each photograph has as name and I need these names to show u

    Hello, I would like to create and print a contact sheet in Photoshop Premier Elements 13. I have managed to do that but I need desperately to be able to place a title on the contact sheet. Also, each photograph has as name and I need these names to show up on the contact sheet when I print them out. If this is not possible I will just return my product. I have an old old version of Photoshop that will do just that but with this new Premiere Elements I cannot find it.

    markc
    What computer operating system is your Premiere Elements 13/13.1 running on?
    Assuming Windows 7, 8, or 8.1 64 bit, open the Elements Organizer 13/13.1 and select your media
    for the Contact Sheet.
    Go to File Menu/Print and set up the Print Dialog for Contact Sheet.
    If you used Edit Menu/Add Caption beforehand, I can see how you can get
    Date
    Caption
    Filename
    under the Print dialog's "4" and even a page number if you have more than 1 page. But, I am not seeing
    where you are going to get a title for each of the contact sheets.
    Any questions or need clarification, please do not hesitate to ask.
    You can get into the Elements Organizer 13/13.1 from the Welcome Screen or by clicking on the Organizer Tab
    at the bottom of the Expert workspace in the Premiere Elements 13/13.1 Editor.
    Please let us know if we have targeted your quesiton..
    Thank you.
    ATR

  • All share functions except email are NOT enabled. I can create and print but order prints is also not working. HELP!

    All share functions except email are NOT enabled. I can create and print but order prints is also not working. HELP!

    Hello
    Please see notes and 4 attachments for your reference. Hopefully this information helps.
    Maureen
    what version of iPhoto are you using? 9.5.1
    what system version are you running? OSX 10.9.4
    what happens when you try to order? See attached picture. I want to share pics to FB & FLICKR etc
    did you make sure you've selected the correct Print Products store in iPhoto's Advanced preference pane? YES
    what fixes have you tried? Restarted computer. I'm not very computer savy. I have had no problems with this in the past.
    where is your library located? I have not moved anything for iphoto.
    did you apply any updates or upgrades just prior to the problem occurring? I can't remember
    are you running a "managed" or "referenced" library? Not sure how to find this out
    what type of Mac? iMac 2.5 GHz Intel Core i5
    how much free space on your boot drive? 12 GB 1333 MHz DDR3 - I have an external hard drive 1 TB

  • Solutions for creating and printing barcode for MII application

    Hi all,
    We need some help on solution about barcode creating and printing for MII applications. Would be greatly appreciated for any suggestions about the best option.
    Our client is running MII 12.x. They also use Crystal Report. They don't have a lot of SAP resources and hence don't want to create Barcode using SAP smart forms. The new application requires reports to be printed out with barcode attached to it. The following are some options that we have identified:
    1. Using Bartender software. MII will provide a XML file and feed to the software. The software can print out the content with the label.
    2. Create a customized action block to create and store barcode on the server. Using a HTML page to display all the content with the jpeg/png version of the barcode. Print out through IE.
    Any other options will be good too. Thanks in advanced for your responses.
    Best regards,
    UMeng

    Thanks for the suggestion.
    One concern I have is this package is developed for v12.0. According to SAP, these action blocks will work in 12.1 but not in 12.2. I've tried to install it on 12.2. The configuration dialog are not working properly.
    Have anybody succefully implemented this package on 12.2?
    Best regards,
    Arnold
    Edited by: Brad Arnold on Mar 2, 2012 11:53 PM
    Edited by: Brad Arnold on Mar 2, 2012 11:55 PM

  • Using macbook pro, how do I create and print labels

    how do I create and print labels using macbook pro

    Do you mean address labels ? Please check out this link
    http://smallbusiness.chron.com/can-print-address-labels-macbook-pro-58714.html
    http://support.apple.com/kb/ht3952

  • Can I transfer and print pictures taken with my iphone?

    Can anyone, please, tell me if it is possible to transfer and print pictures taken with my iphone. I would need to print out a few pictures, but I could not fina any information about transferring or printing out pictures that are on my "Camera Roll" section of my iphone. Thank you very much for any help.

    When you connect your iPhone for the first time after taking a picture, Windows or Mac will pull up a dialog asking what you would like to do with "Digital Camera" or whatever the USB recognized question is saved as.
    With Windows, it will have "Camera and Picture Wizard" which will copy all pictures and save to where you specify or it will ask if you want to print them. **
    You can also change the default selection somehow to change to a new application if you installed such as Paint Shop Pro or Adobe Photoshop. Note that after you check the dialog box "Remember my choice" whatever the wording is, you have to figure out where to change your choice afterwards.
    With Mac, it has iLife to copy the photos for printing.
    An alternative is to save the photos, then burn them to CD, and take it to CVS or a One Hour Photo shop to do it.
    ** The iPhone will still retain it's captured stills and re-ask the same question again and again until you delete the photographs on the camera application.
    Message was edited by: JoeZinVA

  • Can you create and print a hard cover photo album on iPhoto when you only have a iPad,  can someone please help.  Did not see the option to print.

    I am trying to create and print a hard cover photobook using iPhoto on my iPad, can this be done?  Did not see the option.  Can someone please help?

    It can't be done on the iPad using iPhoto for iOS.  You need to use iPhoto for the Mac.

  • I downloaded the Acrobat 11 trial and  I can open the product. During the install it deleted the existing print driver and did not install a new print driver so I CAN Not create and print pdf files.

    I downloaded the Acrobat 11 trial and  I can open the product. During the install it deleted the existing print driver and did not install a new print driver so I CAN Not create and print pdf files.

    What OS? Have you tried a repair and updates from the HELP menu? The updates may be the key.

  • Create and send email issue with UCCX/IP-IVR 8.0 script

    Hi all,
    I am facing issue with create and send email option with script. In my call flow there is an option to offer call to key in their phone number and script need to pass that phone number to supervisor as an email. I have created the script but every time when I key in the phone number is pass through the unsuccessful node. Please find the script as attachment.
    Thanks and Regards,
    Ashfaque

    Hi How Yee,
    Which version of UCCX/IPIVR you are using and what is the type of license? Because this feature is only supported with Premium License. Please check the UCCX data sheet from the below link.
    http://www.cisco.com/en/US/partner/prod/collateral/voicesw/custcosw/ps5693/ps1846/data_sheet_c78-629807.html
    You will get the information under "Integrated IVR Features with Server Software" of table:4.
    Thanks and Regards,
    Ashfaque.

  • How can I view all comments in a Pages doc and print the doc with comments?

    It seems that we can no longer view comments in the margin of a document.  It is also not possible to print the document with comments visible.  Anyone else having this problem?  Pages 09 Help does not even offer an up-to-date explanation.  "Show Comments" only shows color shading.  The option “Show Comments and Changes Pane" does not even exist.  How can I get the comments to print???

    You will have to wait for Apple to fix this deficiency in a forthcoming update to Pages v5. Or, you could use Pages ’09 v4.3, if originally installed before the v5 upgrade, and located in /Applications/iWork '09.
    Otherwise, use another solution (e.g. Office for Mac 2011, LibreOffice).

  • File and Printer Sharing Problem with WRT54G

    I am currently having problems sharing files over my network. My setup consists of:
    3 laptops (wireless)
    1 desktop (wired)
    WRT54G V6.0 router with firmware version 1.00.9.
    All of the computers have File and Printer Sharing enabled, unique names, and are on the same workgroup. However none of the computers can see one another. When I try to view workgroup computers for my network places, the explorer window stops responding for about 30 sec. and then spits out a dialog with the error:
    "Workgroup is not accessable. You might not have permission to use this network resource. Contact the administrator of this server to find out if you have access permissions.
    The list of servers for this workgroup is not currently available."
    I think that this problem has something to do with the router, as I have been successfuly sharing files and a printer with these settings using a microsoft 802.11b router for over a year. After purchasing the linksys and swapping it out with my old router, filesharing no longer functions.
    I have spent a little time browsing the forums and have seen other posts from people with simmiler problems, but was unable to find any solutions.
    Any help would be much appreciated.
    Thanks.

    I'm having the same problems as you are, I have 2 computers on wired the other wireless the router is in between and I can't access from either side, although I can ping and remote connect but just cannot share files across the network. I have looked all over the forums too and there saying to ditch linksys and do something else.
    Its not you thats caused this it is the firmware and the router that have the problems.
    My Specs:
    WRT-54G
    v5.0
    That new firmware update 1.00.9 just isn't working right. I might downgrade my fireware to fix this problem.
    Message Edited by justin2006 on 09-26-200612:24 PM

Maybe you are looking for

  • How to install Exchange Server 2010 with the name of my existing Domain Controller.

    I have my Primary domain Controller as abc.com in 2008 r2 standard. abc.com is registered. I want to set up Fresh Exchange Server 2010 sp2 with the name of the same abc.com domain name. Please guide me the steps how to do that. Waiting for your kind

  • HT4759 how do i install ios 7 on my ipad?

    I purchased a first generation Ipad and have IOS 5.1 and am trying to install IOS 7.0.1 but it keeps saying my Ipad is updated with the IOS 5.1, how do I install the IOS 7.0.1

  • Count of columns in a query

    All, Could anyone please clarify me on , how we can count the column's which were used in a query. Ex:    SELECT ENAME, EMPNO, SAL , JOB FROM EMP;  --Here in the above query, I have taken 4 columns(counted manually) . Instead of counting it manually

  • Can I get back up discs for adobe software that is pre-installed on a computer?

    I am thinking of buying a used Mac, with Master Collection pre-installed on it. Trouble is, it doesn't come with the discs. Can I get a back-up disc of the Adobe software if I have the license? I have bought used Adobe software before and had the lic

  • MATSHITA DVD-R UJ-816 won't play *some* DVDs now (mysteriously!).

    Quite mysteriously, my Mac is refusing to play some of my DVDs. The DVDs aren't scratched or unplayable. I tested them this weekend on someone else's multi-regional player. These DVDs most certainly did play before on this laptop (a late-2003 Titaniu