Wait for Image created with Toolkit.createImage()

I try to create a new image using Toolkit.createImage(byte[]). When I try to proccess this image afterwards with an ImageObserver Container.prepareImage() I get an error returned from Container.checkImage().
It looks like Toolkit.createImage(byte[]) did not finish the image-creation. But how can I wait for it?

Try to use a MediaTracker:
MediaTracker tracker=new MediaTracker(this);
tracker.addImage(image,0);
try
tracker.waitForID(0);
catch(InterruptedException e){}

Similar Messages

  • DrawImage takes long time for images created with Photoshop

    Hello,
    I created a simple program to resize images using the drawImage method and it works very well for images except images which have either been created or modified with Photoshop 8.
    The main block of my code is
    public static BufferedImage scale(  BufferedImage image,
                                          int targetWidth, int targetHeight) {
       int type = (image.getTransparency() == Transparency.OPAQUE) ?
                        BufferedImage.TYPE_INT_RGB :
                        BufferedImage.TYPE_INT_RGB;
       BufferedImage ret = (BufferedImage) image;
       BufferedImage temp = new BufferedImage(targetWidth, targetHeight, type);
       Graphics2D g2 = temp.createGraphics();
       g2.setRenderingHint
             RenderingHints.KEY_INTERPOLATION, 
             RenderingHints.VALUE_INTERPOLATION_BICUBIC
       g2.drawImage(ret, 0, 0, targetWidth, targetHeight, null);
       g2.dispose();
       ret = temp;
       return ret;
    }The program is a little longer, but this is the gist of it.
    When I run a jpg through this program (without Photoshop modifications) , I get the following trace results (when I trace each line of the code) telling me how long each step took in milliseconds:
    Temp BufferedImage: 16
    createGraphics: 78
    drawimage: 31
    dispose: 0
    However, the same image saved in Photoshop (no modifications except saving in Photohop ) gave me the following results:
    Temp BufferedImage: 16
    createGraphics: 78
    drawimage: 27250
    dispose: 0
    The difference is shocking. It took the drawImage process 27 seconds to resize the file in comparison to 0.78 seconds!
    My questions:
    1. Why does it take so much longer for the drawImage to process the file when the file is saved in Photoshop?
    2. Are there any code improvements which will speed up the image drawing?
    Thanks for your help,
    -Rogier

    You saved the file in PNG format. The default PNGImagReader in core java has a habit of occasionally returning TYPE_CUSTOM buffered images. Photoshop 8 probably saves the png file in such a way that TYPE_CUSTOM pops up more.
    And when you draw a TYPE_CUSTOM buffered image onto a graphics context it almost always takes an unbearably long time.
    So a quick fix would be to load the file with the Toolkit instead, and then scale that image.
    Image img = Toolkit.getDefaultToolkit().createImage(/*the file*/);
    new ImageIcon(img);
    //send off image to be scaled A more elaborate fix involves specifying your own type of BufferedImage you want the PNGImageReader to use
    ImageInputStream in = ImageIO.createImageInputStream(/*file*/);
    ImageReader reader = ImageIO.getImageReaders(in).next();
    reader.setInput(in,true,true);
    ImageTypeSpecifier sourceImageType = reader.getImageTypes(0).next();
    ImageReadParam readParam = reader.getDefaultReadParam();
    //to implement
    configureReadParam(sourceImageType, readParam);
    BufferedImage img = reader.read(0,readParam);
    //clean up
    reader.dispose();
    in.close(); The thing that needs to be implemented is the method I called configureReadParam. In this method you would check the color space, color model, and BufferedImage type of the supplied ImageTypeSpecifier and set a new ImageTypeSpecifier if need be. The method would essentially boil down to a series of if statements
    1) If the image type specifier already uses a non-custom BufferedImage, then all is well and we don't need to do anything to the readParam
    2) If the ColorSpace is gray then we create a new ImageTypeSpecifier based on a TYPE_BYTE_GRAY BufferedImage.
    3) If the ColorSpace is gray, but the color model includes alpha, then we need to do the above and also call seSourceBands on the readParam to discard the alpha channel.
    3) If the ColorSpace is RGB and the color model includes alpha, then we create a new ImageTypeSpecifier based on an ARGB BufferedImage.
    4) If the ColorSpace if RGB and the color model doesn't include alpha, then we create a new ImageTypeSpecifier based on TYPE_3BYTE_BGR
    5) If the ColorSpace is not Gray or RGB, then we do nothing to the readParam and ColorConvertOp the resulting image to an RGB image.
    If this looks absolutely daunting to you, then go with the Toolkit approach mentioned first.

  • Rotate Image Created with createImage() ?

    I've been looking around online for a way to do this, but so far the only things I have found are 50+ lines of code. Surely there is a simple way to rotate an image created with the createImage() function?
    Here's some example code with all the tedious stuff already written. Can someone show me a simple way to rotate my image?
    import java.net.*;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class RotImg extends JApplet implements MouseListener {
              URL base;
              MediaTracker mt;
              Image myimg;
         public void init() {
              try{ mt = new MediaTracker(this);
                   base = getCodeBase(); }
              catch(Exception ex){}
              myimg = getImage(base, "myimg.gif");
              mt.addImage(myimg, 1);
              try{ mt.waitForAll(); }
              catch(Exception ex){}
              this.addMouseListener(this);
         public void paint(Graphics g){
              super.paint(g);
              Graphics2D g2 = (Graphics2D) g;
              g2.drawImage(myimg, 20, 20, this);
         public void mouseClicked(MouseEvent e){
              //***** SOME CODE HERE *****//
              // Rotate myimg by 5 degrees
              //******** END CODE ********//
              repaint();
         public void mouseEntered(MouseEvent e){}
         public void mouseExited(MouseEvent e){}
         public void mousePressed(MouseEvent e){}
         public void mouseReleased(MouseEvent e){}
    }Thanks very much for your help!
    null

    //  <applet code="RotationApplet" width="400" height="400"></applet>
    //  use: >appletviewer RotationApplet.java
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    public class RotationApplet extends JApplet {
        RotationAppletPanel rotationPanel;
        public void init() {
            Image image = loadImage();
            rotationPanel = new RotationAppletPanel(image);
            setLayout(new BorderLayout());
            getContentPane().add(rotationPanel);
        private Image loadImage() {
            String path = "images/cougar.jpg";
            Image image = getImage(getCodeBase(), path);
            MediaTracker mt = new MediaTracker(this);
            mt.addImage(image, 0);
            try {
                mt.waitForID(0);
            } catch(InterruptedException e) {
                System.out.println("loading interrupted");
            return image;
    class RotationAppletPanel extends JPanel {
        BufferedImage image;
        double theta = 0;
        final double thetaInc = Math.toRadians(5.0);
        public RotationAppletPanel(Image img) {
            image = convert(img);
            addMouseListener(ml);
        public void rotate() {
            theta += thetaInc;
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            double x = (getWidth() - image.getWidth())/2;
            double y = (getHeight() - image.getHeight())/2;
            AffineTransform at = AffineTransform.getTranslateInstance(x,y);
            at.rotate(theta, image.getWidth()/2, image.getHeight()/2);
            g2.drawRenderedImage(image, at);
        private BufferedImage convert(Image src) {
            int w = src.getWidth(this);
            int h = src.getHeight(this);
            int type = BufferedImage.TYPE_INT_RGB; // options
            BufferedImage dest = new BufferedImage(w,h,type);
            Graphics2D g2 = dest.createGraphics();
            g2.drawImage(src,0,0,this);
            g2.dispose();
            return dest;
        private MouseListener ml = new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                rotate();
    }

  • Suppress NetPrice field for POS created with info records

    Hi ,
    What is the BADI used for Suppressing NetPrice Field for POS created with Inforecords(ME21n and ME22N).
    I dont find any user exit for this, so please can anyone say me what is the Badi used to meet the requirement.
    Thanks in advance,
    Donlad

    Hi sanjay,
    Suppressing in the sense, no changes should be made to net price field.
    The netprice should be suppressed only when po is a Production Po(Identified by account assignemnet Cateogery 'P') and material  has an inforecord.
    for other orders(overhead/nonbillable) using a material has an existing inforecord , the netprice field should not be suppressed.
    Waiting for your respopnse.
    THanks,
    Donald

  • Which table contains net book value for Assets created with AS91.

    Which table contains net book value for Assets created with AS91.
    I have a problem locating where the net book value is stored in SAP.  Is it simply calculated and not stored in any one place?  I am trying to predict how SAP will calculate the net book value for some assets we plan on converting, but my formula doesn't always work consistently and I have not idea what is going on.  If it is stored in a table some place, can anyone please let me know!
    Thank you all

    Hi anar.samadzade & Michael Stewart
    It is not possible to directly get net book value of an any Table. You must migrate the gross book value (acquisition cost) and the accumulated depreciation. SAP will then calculate the NBV.
    Gross Block & Accumulate Dep you will get from Table: ANLC
    http://fixedassetsaccounting.net/migrating-fixed-assets-into-sap-a-harlex-guide/
    Dear anar.samadzade Ask Questions politely
    Regards
    Viswa

  • Table name for Invoice created with PO ref

    hi,
    I required Table name for Invoice created with PO ref.
    Regards,
    Ali

    HI,
    Check the table RSEG: Document Item: Incoming Invoice
    Look for the fields BELNR and EBELN
    Regards
    KK

  • I WANT TO BUY A MAC BOOK PRO. MUST I WAIT FOR THE ONE WITH RETINA DISPLAY. WILL THE FACT THAT THERE IS NO CD ROAM BE A PROBLEM. CAN YOU USE A EXSTERNAL CD ROAM ON A MAC?

    I WANT TO BUY A MAC BOOK PRO. MUST I WAIT FOR THE ONE WITH RETINA DISPLAY. WILL THE FACT THAT THERE IS NO CD ROAM BE A PROBLEM? CAN YOU USE AN EXSTERNAL CD ROAM WITH A MAC?

    Apple will gladly sell you a color coordinated and texture matching external SuperDrive to go with your Retina'ized MBP for about $80 bucks.
    Note that those models are completely sealed with no serviceable or upgradeable parts inside. So if you decide to bite the bullet, be sure to customize its guts to your heart's content from the get-go as no further change will be possible. This means CPU speed, amount of RAM and size of the solid state drive. Other external options, like the Superdrive, can be added later.

  • Unable to unlock encrypted disk images created with Snow Leopard using Lion

    Anyone else unable to unlock encrypted disk images created with Leopard and Snow Leopard with Lion?  I know that they made changes with the release of FileVault 2 on Lion and Snow Leopard cannot use Lion encrypted disks but I thought it was backwards compatible where Lion should still be able to work with Snow Leopard created images (it was in the pre-release versions of Lion).
    When attempting to mount an encrypted disk image created with Snow Leopard on Lion the normal password prompt appears but then just reappears every time the password is entered and does not unlock and mount the image.  I'm positive the correct password is being entered and it works just fine when done on a machine running Snow Leopard.

    Not in cases when the computer successfully boots to one OS but produces three beeps when an attempt is made to boot it to another. If it really was a RAM problem that serious, the computer wouldn't get as far as checking the OS version, and it has no problems booting Lion. In the event of a minor RAM problem, it wouldn't produce three beeps like that at all.
    (67955)

  • No quicklook/preview for documents created with Pages 5.5!

    Before opening files and find you can hit the spacebar and have a preview of most of the file types.
    This always worked well with Pages until the newest version 5.5. Now I can only preview the files created with older versions of Pages.
    Every file created with the new version only shows the icon or a very blurred image but not a readable preview of the file itself like before. Even worse, if you change a file with Pages 5.5 you also can't see a preview any more.
    Apple's telephone hotline had no solution.
    Any idea for a solution would be very helpful as my DevonThink database also uses the preview feature and opening any file before being able to have a quick look on it is really annoying.
    Has anybody experienced this problem?

    There's no preview on iPad or iPhone either for these files. You can't see the content in DevonThink to go.

  • I am having an iphone 4 and it is not working. i am trying to restore it on itunes directly but it stays at waiting for iphone status with no errors and the iphone goes into a mode where it keeps restarting continuously with apple logo on the screen

    the iphone goes from recovery mode to some other mode where it keeps restarting with apple logo flashing on the screen continuously. and there is no error in itunes at all which stays in "waiting for iphone" status

    Hi there yaswanthfromcumbum,
    You may find the troubleshooting steps in the article below helpful.
    If you can't update or restore your iOS device
    http://support.apple.com/kb/ht1808
    -Griff W. 

  • To wait or not to wait for BB10 device with physical keyboard

    Hello everyone. I'm really psyched about BB10 but am debating whether or not to buy the touch screen device at launch or wait for a Bold-lie device. I really dislike the softkeyboard on other phones but I've read the BB10 softkeyboard is beyond others in comparison. Can anyone offer some advice?
    Solved!
    Go to Solution.

    Honestly, I am fine with the keyboard intuitive Dev Alpha, however, is subjective ..
    My advice would be to wait for the release in stores to prove it directly
    If U like my post click on LIKE

  • Create transaction custom for report created with transaction IME1

    Hi,
    I created a report custom for investment management with transaction IME1.
    Now, I have to link this report to a transaction custom.
    Please, could you help me?
    THanks
    Regards

    se93 type a new Z tcode and create new.. from the drop down list select "program and selection screen (report transaction)"
    go back to your report screen from menu; "system --> status" and get the program name for the report.
    type this report to the se93 screen for the t.code. and save...

  • Wait for an agent with best skill and loop after that.

    I want to solve the following situation:
    I have three skills (A, B, C) with different skill levels for each agent. C is the "everything else topic" . The caller selects the toppic which is equivalent to the skills. Of course I want the call to be forwarded to the best skilled agent.
    Let's assume the calles selects topic A and all Agents with Skilllevel > 5 for  A are currently talking. I want to hold the caller for 30 seconds to wait for one of these Agents. After 30 seconds I would like to forward the call to the agent with the highest skill level A.
    And of course I want to avoid the caller to wait the 30 seconds if no Agent with skilllevel > 5 is on duty.
    Currently I have one CSQ for each topic and I expect a skillevel > 5 for the agents serving this CSQ.
    At first I put the call in the CSQ for A and play a prompt with 30 seconds MOH, if no agent becomes available I put the call in the CSQ for C and loop the caller there. But now the best agent for C get's the call.
    I appreciate any hints on that.
    Christian

    Don't queue in C unless there are at minimum X ready agents.  You can define X as 1 to start, then play with the number to see how it affects wait times and dequeues.
    select resource (csq_a)     connected          end     queued          label loop          ready_in_c = get reporting stats(csq_c, ready resources)          if (ready_in_c >= 1)               true                    /* at least one person idle and ready in C                    select resource(csq_c)                         connected                              end                         queued                              /* oops! we just missed them. */                              /* if ready_in_c was > 1, this dequeue step will not execute */                              /* instead, the script jumps to the select resource step for csq_c */                              /* and tries the next agent automatically.  only when there are no */                              /* idle and ready agents do we dequeue the caller, so that an agent */                              /* servicing csq_a can take the call */                              dequeue(csq_c)               false                    /* no one available in C */               play prompt(you are important to us)               call hold               delay 30               call unhold               goto loop

  • Need to get rid of persistent images created with as3 - pls help

    I have used the following as3 code, courtesy of Jody Hall at theflashconnection.com .  It's a drag and drop that works great. Problem is the drag and drop images persist when I move on to other frames. How do I clear the images when finished so they don't appear in subsequent frames? Thank you in advance.
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    var sndExplode:explode_sound;
    var sndExplodeChannel:SoundChannel;
    var dragArray:Array = [host1, agent1, physical1, social1, host2, agent2, physical2, social2, host3, agent3, physical3, social3];
    var matchArray:Array = [targethost1, targetagent1, targetphysical1, targetsocial1, targethost2, targetagent2, targetphysical2, targetsocial2, targethost3, targetagent3, targetphysical3, targetsocial3];
    var currentClip:MovieClip;
    var startX:Number;
    var startY:Number;
    for(var i:int = 0; i < dragArray.length; i++) {
        dragArray[i].buttonMode = true;
        dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
        matchArray[i].alpha = 0.2;
    function item_onMouseDown(event:MouseEvent):void {
        currentClip = MovieClip(event.currentTarget);
        startX = currentClip.x;
        startY = currentClip.y;
        addChild(currentClip); //bring to the front
        currentClip.startDrag();
        stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
    function stage_onMouseUp(event:MouseEvent):void {
        stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
        currentClip.stopDrag();
        var index:int = dragArray.indexOf(currentClip);
        var matchClip:MovieClip = MovieClip(matchArray[index]);
        if(matchClip.hitTestPoint(currentClip.x, currentClip.y, true)) {
            //a match was made! position the clip on the matching clip:
            currentClip.x = matchClip.x;
            currentClip.y = matchClip.y;
            //make it not draggable anymore:
            currentClip.removeEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
            currentClip.buttonMode = false;
            sndExplode=new explode_sound();
            sndExplodeChannel=sndExplode.play();
        } else {
            //match was not made, so send the clip back where it started:
            currentClip.x = startX;
            currentClip.y = startY;
    DRAG AND DROP (I JUST DID THE LAST FOUR FOR THIS EXAMPLE)
    MOVING ON TO NEXT FRAME, YOU STILL SEE THE RECTANGLES.

    Thank you SO muchNed Murphy
    I'm a newbie to AS3 and I was trying to figure it out for past 2 weeks that why did swapChildren or setChildIndex or addChild, all of these made my Target Movieclip remain/duplicate/persist on the stage even after the layer containing the Target Movieclip has blank keyframes. I surfed so many forums and tutorials for the answer but turns out it was my lack of knowledge of basic concepts. I remember checking out this specific forum as well past week but due to it being "Not Answered" I skipped it. This should be marked as a "Correct Answer", The Empty MovieClip did the trick!
    I needed this solution for a Drag and Drop game, so that the current item that is being dragged is above all other graphic layers. And when all items are dropped on their correct targets, there is gotoAndPlay to Success frame label.
    I created a movieclip on the top layer with the same dimensions as the stage and put it at x=0 y=0 position. Instance name: emptymc
    And deleted the emptymc from the timeline during the Success frame label.
    Here is some code I used,
    1. MovieClip.prototype.bringToFront = function():void {
       emptymc.addChild(this);
    2.  function startDragging(event:MouseEvent):void {
      event.currentTarget.startDrag();
      event.currentTarget.bringToFront();
    I didn't know how to put the addChild and refer to the currentTarget in the startDragging function itself, for example
    emptymc.addChild(event.currentTarget);
    - This one didn't work inside the startDragging function "emptymc.addChild(this); "
    Is there a correct way I could have done it properly?
    Thanks,
    Dipak.

  • Choosing Color Profiles for Images Created on Film

    I just finished sending feedback to Adobe on one of its tutorials. The following is a copy of my message explaining my present predicament.
    << I have scanned film negatives and positive film transparencies dating back to the 1950's .I was the creator of most of these images but I do not remember the make or model of the cameras I was using at any point in time prior to 1974 and they all lack metadata. Prior to 2000 I used iPhoto and PS Elements for scanning, toning and development. Thus I can only guess what color profile I should use. I want to create TIFFS that will serve a dual purpose: exporting two formats, one for electronic sharing and the other for printing. On the Adobe CC, if I guess wrong, LR 5.6 64bit crashes immediately. Prior stand alone versions of LR and CS6 let you know that you had a color inconsistency, but they did not crash when you had made a wrong choice between srgb and ProPhoto. ACC gives me more options, but no warnings unless I am missing something your Help Files should contain.>>
    David Krupp Win7 64bit
    Chicago, IL 773-281-6278. [email protected]

    I guess I am going to throw caution to the wind and see what happens.
    Only one way to find out, Right
    Though I did go back and lighten my images. Also
    Ran color synch utility, which fixed 11 corrupt color profiles.(none of the 11 profiles pertained to i photo)
    I guess I am afraid to use pref setter,, to set the key embed color profile.
    Confused as to what that means??? Does that mean that all my CS Adobe-RGB jpegs will keep their color profile???
    Also implanted one image as an SRGB vs the rest which will all be AdobeRGB
    Oddly my color management in CS is almost Flawless. Yet, get me out of CS and I am completely lost!!!! Complicated stuff
    Toad, I did want to pass on that AdobeRGB 1998 is a much more robust color profile then SRGB especially when it come to printing on Epson. It might be worth experimenting with and if you really want to get into it there is also
    Pro photo RGB which is Huge color space, but a beast to work with
    Here is a link
    http://www.luminous-landscape.com/tutorials/prophoto-rgb.shtml
    Will report back on my book
    TF

Maybe you are looking for

  • Error While Doing Post Goods Issue

    Hi SD Gurus While I am Doing PGI for Standard Order, I am Getting the following Error. Version : 5.0 Clien: 800 Runtime Errors         PXA_NO_FREE_SPACE Date and Time          24.01.2008 23:50:48 Short dump has not been completely stored (too big) Sh

  • USB/ Firewire Ports not recognized...

    My iMac will not recognize my iPod, printer, camera, or anything that is plugged into it. What could be the problem? Thank you so much for your help!!!

  • Adding Hyper-V features to Windows Server 2012

    I have already set up a virtual machine with Windows server 2012, when I try to add Hyper-V features it prompts error: Hyper-V cannot be installed: The processor does not have required visualization capability. The VM properties is: Memory 1GB Proces

  • FSRM report limits using PowerShell

    I am following this article: http://blogs.technet.com/b/filecab/archive/2014/05/20/set-fsrm-storage-report-limits-using-powershell.aspx I did have this working just fine, but after installing Windows Updates today on a 2012 R2 box this functionality

  • Keyboard disabled during install

    Attempting to install xp on my my macpro desktop. When I get to the point where I have to press "enter" the keyboard appears to be disabled. Any thoughts? thanks That's in Snow Leopard, by the way.