Why Graphics.drawImage() can't work?

Hi Veterans,
I met some problems when I create an image by calling the Graphics.drawImage() method. Firstly, I created an off-screen image by calling the method frame.createImage(800, 640), then I was drawing some graphical elements on the the graphics acquired from the offscreen image, like drawString(), drawLine. And the most important step is as follows, I want to append another image from the file system to the current one by calling drawImage(Image img, int x, int y, ImageObserver frame), but it can't work, I got the appended image by calling Toolkit.getDefaultToolkit().createImage("D:\\abc.gif"). But I am not sure if it is a correct way to get an image from the file system. After that, I will use a 3rd party utitliy to generate new gif image. But when I view the new generated image, it only include the grahpical elements I drew by drawString(), drawLine, and the drawImage() seems can't work. Why?
I post the code snippet for reference.
Any help is appreciated!
               frame=new Frame();
               frame.addNotify();
               Image offscreen = frame.createImage(800, 800);
               g = (Graphics2D) offscreen.getGraphics();
               g.setFont(new Font("Dialog",Font.PLAIN,12));
               g.drawString("Owner ID:",10,10);
               g.drawString("2238",90,10);
               g.drawString("Order No.:",10,40);
               Image image = Toolkit.getDefaultToolkit().createImage("D:\\barcode.gif");
               System.out.println("[Image Width:] " + image.getWidth(frame)); //the output is -1, why?
g.drawImage(image, 0, 0, frame); //seems can't work

This isn't right. The Toolkit returned by getDefaultToolkit has an implementation for all these methods. The issue here is that you are calling getWidth on the Image before the Image has been loaded from your gif file. What you need to do is to call getWidth(ImageObserver) and then, if the width comes back as -1 wait for the ImageObserver to notify you that it has loaded the width attribute of the image. Take a look at
http://java.sun.com/docs/books/tutorial/uiswing/painting/loadingImages.html
Huw

Similar Messages

  • Why badi HRPAD00INFTY can't work in t-code PTMW?

    hi:
    why badi HRPAD00INFTY can't work in t-code PTMW? if I want to do enhancement about PT infty in PTMW,what should i do?

    Please refer to help document for BAPI:HRPAD00INFTY which allows you to react to specific events in Personnel Administration. If you need logic in TMW, implement BADI  PT_BLP_USER. Further information can be found in section 6.a of SAP Note 447097.
    Regards
    Chetan

  • Why my PermissionsCommand can not work?

    Thers is a SAP standard command named "permissions" that you can find in "System Admin>System configuration>content management>user interface>commands".It is drived from the java class "com.sapportals.wcm.rendering.uicommand.cm.UIPermissionsCommand".
    I download the java class and decompile into java file.In netweaver development studio,I create a new project and copy the java code into a new class of the project and deploy it into my portal.In portal I link the class to a command named "permisssiontest",but unlucky the command doesnot work.
    Why my permission command can not work?

    Hi Shi,
        Could you give me more details about this issue ? After deploy, have you created a new command and assign it a group command in a layout set.
       Here:
       https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/kmc/Knowledge%20Management%20and%20Collaboration%20Developers%20Guide.html
       You can find this example: SimpleOneStepScreenFlow. You can use it as template.
       We had to write a new permission command and it worked fine.
    Patricio.

  • Why dbms_metadata.get_ddl can not work for db link?

    db: 10.2.4
    os: RH linux 5
    our problem is that we can not get ddl from dbms_metadata.get_ddl for database link, however the db link does exist here as below.
    SQL> select * from dba_db_links where owner='XXRPTH';
    OWNER DB_LINK USERNAME HOST CREATED
    XXR TO_DOPDB.XXR.COM TEST db_opdb 18-FEB-08
    XXR XXRPTH_OPDBC.XXR.COM TEST db_opdb 15-JUL-08
    XXR XXRPTH_BLIS.XXR.COM BLIS dbls 02-JUN-08
    SQL> select dbms_metadata.get_ddl('DB_LINK','XXRPTH_OPDBC.XXR.COM','XXR') from dual;
    ERROR:
    ORA-31603: object "XXRPTH_OPDBC.XXR.COM" of type DB_LINK not found in schema "XXR"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_METADATA", line 2806
    ORA-06512: at "SYS.DBMS_METADATA", line 4333
    ORA-06512: at line 1
    appreciate for any guides
    thanks

    I ran into this in a slightly different form, I can't remember all the rules and details, but to work around it I had to specify a fake name appendage in the db link creation in order to keep it from automatically appending the global domain.
    Something like
    create database link abcdef.remotealias connect to ... using 'remotealias'
    rather than
    create database link abcdef connect to... using 'remotealias'
    At least I think it was fake, I was flopping around trying things until I got it to work, and I wound up making it the same as the tnsnames alias. I think I decided I didn't have to, but left it as the lesser of two confusions, and was miffed that the creation scripts I had been using for years suddenly had to be fixed. Yeah, it was my own damned fault, but I still think the way this works is crazy. Now hopefully someone will explain this simply so I look foolish.

  • Why database link can't work?!

    I have two machines: One with Oracle 8.1.5 Enterprise on NT
    (Login user is test1/test1@nt),
    the other with Oracle 8.1.5 standard edition on ScoUnixware 7.1.1
    (Login user is test2/test2@unix).
    I created a table named aa on NT, a table named bb on Unix.
    Then, I created two database link:
    connect test1/test1@nt;
    create public database link link2
    connect to test2 identified by test2 using 'unix';
    connect test2/test2@unix;
    create public database link link1
    connect to test1 identified by test1 using 'nt';
    After I successfully created two database links.
    I run the following SQL script:
    connect test1/test1@nt;
    desc bb@link2
    (This SQL return error:
    ORA-02085: database link link2 connect to ora2
    (ora2 is SID under unix)
    connect test2/test2@unix;
    desc aa@link1
    (This SQL return correct result.)
    Why?!
    null

    This does not appear to be related to sql server, so posting to an access forum would likely be more effective.

  • Itunes can't work because of old bonjour??

    i don't know why my itunes can't work
    sometimes it can, sometimes it can't
    i keep install and uninstall itunes almost everyday
    i tried to uninstall itunes before i install the new one, but i can't get rid of Bonjour. i remove all the programs and files as the Apple's instructions, but i can't remove the Bonjour folder.
    "mdnsNSP.dll" is the only thing left
    i tried to delete "mdnsNSP.dll", but everytime it says that "mdnsNSP.dll" is being used. then i opened the Task Manager, i can't find the name. so i can't either end the process or delete it.
    (i wonder if there's something wrong with my computer. virus?)
    *please help me !!! i need music=(*

    http://docs.info.apple.com/article.html?artnum=304424

  • Why does Acrobat suddenly not work on my Mac (won't open pdf files from a web page), yet I can open them from my iPhone? Everything worked fine yesteray.

    Hello:
    I have a Mac running OS 10.8.5 and I use Acrobat Pro and Acrobat Reader. Today for some reason, any time I try and access a pdf file from a web page, it won't open. I get a blank window. PDF files already on my computer open fine and I can create PDF files from Word docs, but I can't download or view any pdf file from any web page. Strangely, PDF files on web pages open just fine on my iPhone.
    I checked that both my copy of Acrobat Pro and Acrobat Reader are up-to-date. They are.
    I checked that my copy of Firefox is up-to-date. It is. And nothing changed with Firefox within the last 24 hours.
    I am a humble computer end-user. I am baffled as to why this would suddenly not work. I have not changed any settings, etc. Any help or suggestions would be greatly appreciated.

    Thank you.
    I checked your instructions you sent and as far as I can tell all of my settings, etc for Firefox (plugin updates and preferences) are correct but I am having the same problem.
    However, everything works in Safari. I don't have time to attempt to diagnose why Firefox no longer works. I will just switch to Safari.
    Many thanks.
    Charles
    Charles Deister
    (503) 949-5762
    [email protected]<applewebdata://81CB4171-226F-49DF-BD59-A38A7360B3FB/[email protected]>
            PO Box 5032
         Salem, OR 97304
    http://www.pilotstrat.com<http://www.pilotstrat.com/>
    This transmission (including any attachments) may contain confidential information, privileged material, or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

  • I have ad Apple ID on my iPad , when I use the apple on my iPhone for the first time, I put in my Apple ID for the iPad, didn't work. Need to create a new one. Why? How can I just use my iPad ID on my iPhone?

    I have ad Apple ID on my iPad , when I use the apple on my iPhone for the first time, I put in my Apple ID for the iPad, didn't work. Need to create a new one. Why? How can I just use my iPad ID on my iPhone?

    Hi kamfong,
    Went to Settings where?
    If you want to use your exisiting Apple ID on your iPad, you need to:
    1.     Go to Settings>iTunes & App Store and sign out the new ID, and then sign on the old one
    2.     Go to Settings>iCloud, scroll to the bottom and delete the iCloud account, and the sign back onto iCloud using the old ID
    You still have not indindated why you are saying that using your old ID originally "didn't work". What do you mean by that? Did you get some sort of error when you tried to sign on with your exisiting Apple ID?
    Cheers,
    GB

  • In photoshop CS6 extended my 3D-extrusie does not work. Why? And can I fix this? I am a mac user. Pl

    In photoshop CS6 extended my 3D-extrusie does not work. Why? And can I fix this? I am a mac user. Please help?

    I have paid the full extended version, but it is not working. See my screenshots.

  • HT3529 Can someone help me understand why my iMessage no longer works on my iPad

    Can someone help me understand why my iMessage no longer works on my iPad

    iOS: Troubleshooting Messages
    iOS: Troubleshooting FaceTime and iMessage activation

  • How do I save a photo after I have zoomed in on it?  I want to save the zoom-in as a new photo and can't work out why this doesn't work the same way saving a cropped image, or adjusted image does.  Thank you.

    How do I save an image after I have zoomed in on it?  I can't work out why I can't save a zoom-in the same way
    I can save a cropped image or an adjusted image. Thanks, Lily A.

    Hi Matt, thanks for your reply.  Have realised that Zoom in Iphoto is just  a viewing tool and not an editing tool.
    Was creating beautiful abstractions by zooming in and wanted to create a new image of the result.   Have since discovered that cropping after zooming takes me a little way to where I want to go but it isn't the same effect.  Will perhaps have to try to create it when actually shooting.  Am doing a photoshop course in February and maybe will learn a bit more then, too.  Am pretty much an amateur just finding my way.
    Thanks again,
    Best, Lily

  • I keep getting "Unable to connect" for my firefox. It was working yesterday and I turned my computer off. I can get to the web using internet explorer 9. I don't know why my firefox is not working. Everything else is working. HELP....

    I keep getting "Unable to connect" for my firefox. It was working yesterday and I turned my computer off. I can get to the web using internet explorer 9. I don't know why my firefox is not working. Everything else is working.

    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.com/kb/Server+not+found
    *https://support.mozilla.com/kb/Firewalls

  • My external Apple USB Keyboard letters doesn't work, but the numbers do. Why and how can I fix this issue?

    My external Apple USB Keyboard letters doesn't work, but the numbers do. Why and how can I fix this issue? Also, When I open the Keyboard Viewer, the letters will highlight only if I hold the modifier key(s) "Control" or "Control and Option". I really need help with this. I don't have any other computer to try it on, so I will have to test it on a friends computer sometime. But perhaps solutions that I can try right now? Thanks.

    Hello there, IDuncan23.
    The following Knowledge Base article has some great troubleshooting steps you can follow to work on resolving your keyboard issue:
    One or more keys on the keyboard do not respond
    http://support.apple.com/kb/ts1381
    Thanks for reaching Apple Support Communities.
    Cheers,
    Pedro D.

  • Hi , please tell me why my ipod doesn't work ... when i conect it to my pc nothing happen .. and i can turn on my ipod .. why ? please help me

    hi , please tell me why my ipod doesn't work ... when i conect it to my pc nothing happen .. and i can turn on my ipod .. why ? please help me

    Go to
    http://bt.custhelp.com/app/answers/detail/a_id/47531
    and follow the instructions
    This was put up by BT several months ago as part of the advance notification that the Yahoo service through them was closing

  • Why does the clone stamp work when I go from a darker colour to a lighter colour but not the other way around. How can I lighten up a dark area? Lasso tool takes from the wrong area too.

    Why does the clone stamp work when I go from a darker color to a lighter color but not the other way around? How can I lighted a dark area? The Lasso tool takes from the wrong area.

    c.pfaffenbichler wrote:
    Why do you use the Blend Modes Lighter and Darker at all in this case and not simply Normal?
    And what kept you from posting a screenshot?
    I borrowed the image below for an HDR workshop I ran at the 2010 PSNZ National Convention, to demonstrate a method of removing halos.  You'll remember that halos were a serious problem with early HDR, and while the halos in this image were caused by over sharpening, they are perfect for demonstrating this technique.
    It relies on the fact that halos so often tend to put a lighter tone between the two areas where sharpening is being applied. Whether that is the sky abutting a dark line of hills, or the rock and little tower as in this image.  I've uploaded it at the size it was supplied to me at (about 2700 pixels wide).  So
    Click to open the full image, right click and copy, and paste into Photoshop.
    Select the clone tool, and set its blend mode to Darken.
    Try to sample on a line horizontal to where you want to clone, to give the best tonal match, and start cloning.
    Because the sky is darker than the halo, it overwrites it. But the rock is darker than the sky, so it has no affect.
    It works even better if you clone on a new layer also set to Darken.  No masking, just Photoshop blend mode magic.
    You can also fix the little tower. Use a great big brush — just remember to sample horizontal to match the horizon.
    Back then I was using the same trick with CAs after forgetting to fix them in ACR, and having done too much work to start again after spotting the problem.

Maybe you are looking for

  • No field in current record - message

    Access2007.accd of an old db built circa 90s .mdb;  Main form, with single form Sub form2, with continuous Sub form3 Main form has a Combobox1 to select record from Table 1 Sub form2 has a Combobox2 in its header to select record from Table 2 (Many t

  • The new upgrade with Itunes will not install

    I have tried to download the new update for ITunes and it doesn't install correctly.  now it is missing a file and i can't even open it

  • MS CRM 2013 : F5/refresh the page and creates new record

    Hi All, Refresh the saved form again open as new record. I have opened the phone call form from member entity, phone call opened has a new window. I have entered data and save the form and it saved the data.If same form I refresh then it creates as a

  • I have to make my ejb's BMP

    Hi, In my bean implementations I have to extract certain fields from finder methods to put them in to ejb-ql's (I want to use CMP). eg; findByProductDefinitionAndRetrievalDate( ProductDefinition productDefinition, Calendar retrievalDate ) in this fin

  • Help updating from 10.7.4?

    Hello! I can not update my system from os x 10.7.4. I have been trying for months now and have read posts from others experiencing the same issues. I have followed the advice of others to no avail. I can't update iTunes either. I have used the regula