Image getwidth() getheight() problem

When i run the code below first time it returns like;
width=-1
height=-1
but when i refresh the page and runing code for secad time width and height returns correct;
why this happen, i couldnt solve....need help,any advice?thank you
Image resmim = Toolkit.getDefaultToolkit().getImage(klasor_adres+resim_adi);
int width=resmim.getWidth(null);
int height=resmim.getHeight(null);

i have found the problem...the problem caused by this;
we must control for the image to be fully loaded to servlet and do this by adding a media tracker...
Image resmim = Toolkit.getDefaultToolkit().getImage(klasor_adres+resim_adi);
          MediaTracker mediaTracker = new MediaTracker(new Container());
          mediaTracker.addImage(resmim, 0);
          mediaTracker.waitForID(0);then we make get width and height operations

Similar Messages

  • Image getWidth & getHeight

    I got this problem in getting the size of the image display on the screen. I try to used getWidth & getHeight and print it out but the value is 0. I try many time will different combination but still can't.
    This is the example:
    map = getToolkit().getImage("Map3.jpg");
    MediaTracker track=new MediaTracker(this);
    track.addImage(map,0);
    try{track.waitForID(0);}
    catch(InterruptedException ie){}
    int w=this.getWidth(map);
    int h=this.getHeight(map);
    Actually, I am trying to resize the image to which fit the JPanel I created but fail. Any idea?

    I presume you mean to be using map.getWidth(this) and map.getHeight(this)?
    It's sufficient to use map.getWidth(null) and map.getHeight(null) in this context.
    However, are you sure that the image is being loaded?
    Put the image in the root directory of your project and try using "/Map3.jpg" instead.
    Hope this helps.

  • Java.awt.Image getWidth() and getHeight() not working!

    Right- this is want I want to do.
    I have a background image which is added as a background image to a third party API class which extends Java.awt.Container. Such container is then added to the Content Pane of MyClass (which extends JFrame)
    I want to read the width and height of the image and resize MyClass accordingly.
    Problem is calling theImage.getWidth(MyClass.this) or theImage.getWidth(theThirdPartyAPIContainer) always return -1 and -1 denoting that no information is available.
    What do I need to do to obtain the height and width?

    Post here, cos don't know your email.
    Anyway
    - Can't use setPreferredSize because the Conatiner which is added to the ContentPane is a Awt Component not a Swing JComponent!
    - Also, the background is added AFTER the this.pack()and this.show().
    -I figured out that I could access Insets.top, Insets.left, Insets.right, Insets.bottom.
    I have basically the following
    |JMenuBar |
    L____________________________________________|
    | |
    | |
    | |
    | Third Party Class extending java.awt.Container |
    | containing an image of known size |
    | |
    L____________________________________________|
    I am fine for the width I do
    Insets frameInsets = this.getInsets();
    width = image.getWidth() + frameInsets.left + frameInsets.right;
    Height is the problem
    After some Trial an error it LOOKS on Solaris as if the following is right-
    height = image.getHeight()+frameInsets.top+ myJMenuBar.getSize()+getHeight+ myJMenuBar.getInsets().top + myJMenuBar.getInsets().bottom
    I cannot comprehend whether this is just a coincidence or not as I don't know why frameInsets.bottom should in any case be excluded.
    Here are the dimensions-
    frameInsets.left = 6
    frameInsets.right= 6
    frameInsets.top =28
    frameInsets.bottom = 6
    JMenuBar height = 23
    JMenuBar's Insets.top = 1
    JMenuBar's Insets.bottom = 1
    What should be the 'correct' calculations and does the Insets for the JMenuBar and the JFrame overlaps?

  • Image.getWidth(null) and image..getHeight(null)  returns -1

    Hi ,
    Plz tell me whats wrong with code
    import java.awt.Image;
    import java.awt.Toolkit;
    public class ImgSize {
        public static void main(String args[]) {
            Image image = Toolkit.getDefaultToolkit().getImage("Picture.jpg");
            double width = image.getWidth(null);
            double height = image.getHeight(null);
            System.out.println("width :" + width + "-- height :" + height);
            getImageDimesion("Picture.jpg");
        public static void getImageDimesion(String abc) {
            Image image = Toolkit.getDefaultToolkit().getImage(abc);
            double width = image.getWidth(null);
            double height = image.getHeight(null);
            System.out.println("width :" + width + "-- height :" + height);
    }output:
    width :-1.0-- height :-1.0
    width :2592.0-- height :1944.0
    There is no difference in main function getWidth/ getHeight and function getImageDimension getWidth/ getHeight
    If u remove getWidth and getHeigth in the main function i.e comment the 1st four lines in main function then the output is
    Output
    width :-1.0-- height :-1.0
    Plz help in understanding this.
    Thanks
    Venkat

    Toolkit images are not loaded until they are first drawn or you request a property from it (such as getWidth). To force the image to load and wait for it to finish loading, you can use the MediaTracker class. The ImageIcon class has one built in.
    Image image = Toolkit.getDefaultToolkit().getImage("Picture.jpg");
    new ImageIcon(image); //loads the image

  • Problems with Image.getWidth()

    I need to have the dimensions (width and height) of an image available, though the image will never be displayed. I have tried using the image.getWidth(this) function outside of the JPanel's paint() method, but to no avail. Actually, only within the paint method was I able to retrieve the information that I needed. So, my question is: how can I gain this information about an image without it being drawn to the screen?
    I had heard that an image, though retrieved and registered into a MediaTracker, is not really "loaded" until it is used or displayed. Is this true?

    Yes, I have been experimenting with the ImageObserver.ImageUpdate() method, but I am a bit unfamiliar with it. Do you know of a decent reference? I am new to Java and the introductory books I have only glean over the topic. I assume I am to be concerned with the ALLBITS flag parameter of the imageObserver method?

  • Please verify my account so i can post an image of my problem. Thanks. Adam.

    Please verify my account so i can post an image of my problem. Thanks. Adam.

    All future people who find this thread - Click the link below and look for the current verification thread as a sticky:
    https://social.technet.microsoft.com/Forums/en-US/home?forum=reportabug
    EDIT: Clarification - accounts will be automatically verified after 15
    points have been accumulated.
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • Iphoto gives message "no images were selected" when hit print button.  Yet the the images are clearly selected in the print window.  I've printed hundreds of images without a problem before.  Iphoto 6.0.6, MAC 10.5.8

    Iphoto gives message "no images were selected" when hit print button.  Yet the the images are clearly selected in the print window.  I've printed hundreds of images without a problem before.  Iphoto 6.0.6, MAC 10.5.8, Suggestions?

    I have recently started having this problem in PSE8. The Adobe workaround
    did work, but I don't fancy having to re register each time I use it.
    What I have discovered is that it's nothing to do with the image metadata as it occurs before any image is opened.
    It SEEMS to only occur if you use file/open with to open an image in the editor - IE start PSE with that command.
    If you close elements down, and start it using programs/PSE/Elements (or your desktop shortcut) - the panorama feature magically works.
    Each time I've opened the editor 'automatically' using image/open with, it seems to create the problem.
    Hope this helps

  • Image.getWidth(ImageObserver obs) returns -1

    hello everyone i have used following code to load an image
    URL location=Sprite.class.getClassLoader().getResource(path);
        img=Toolkit.getDefaultToolkit().getImage(location);and this code to draw an image:
    g2d.drawImage(img, x, y, this);now i need to know the width and height of image for detecting collision.
    getWidth() and getHeight() returns -1.
    System.out.println(img.getWidth(this));my images are getting displayed in the frame.but when i try to access width and height of an image then it returns -1 which means width and height of image is not known yet.
    help !!
    thanks.

    sorry.
    This problem is in my game code.Since the code is very long so i am giving a small code reflecting my problem
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.net.URL;
    import javax.swing.*;
    import java.awt.Graphics;
    public class Sprite extends JPanel
    private JFrame frame;
    private Image img;
    public Sprite()
    frame=new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,400);
    frame.getContentPane().add(this);
    frame.setVisible(true);
    URL location=Sprite.class.getClassLoader().getResource("small.jpg");
    img=Toolkit.getDefaultToolkit().getImage(location);
    this.repaint();
    System.out.println(img.getWidth(null));
    public void paintComponent(Graphics g)
    g.drawImage(img,150,150,this);
    public static void main(String[] args)
    new Sprite();
    }So i want the width and height of an image.But when i try to get it, it just returns -1 which means width and height is not known yet, according to java doc.
    if i use img=new ImageIcon("small.jpg").getImage() to load an image and if i access the width and height of an image using img.getWidth(ImageObserver obs) then i get correct value of width and height.
    i want to use above code that i provided to load an image.So pls help me out.Why it is returning -1 ?.
    Edited by: JGarage on Dec 6, 2008 7:59 AM
    Edited by: JGarage on Dec 6, 2008 8:00 AM

  • Image processing Manupulation problem!!!

    Dear all,
    God Morning! hope u all are fine .. i have an issue regarding Image processing Manipulation.
    i want to give u all the details.. what i have done so far in java.
    i have used third party tool of java called ImageJ editor for image manipulation.i got the source of it i have made neccessary customization to store / fetch the image from my table (Database).now this editor is working fine when i click on open option from menu bar it fetches the image from database and after fetching it put the image on container where one can edit/ modify the image and save it back to the table.
    the above proceeds me to display or store the edited image on the database . now i just want to integrate the editor on browser ..
    how to call the class file when i click on the link on specified page and also how to pass parameter from jsp page to java class file.??
    please help me to sort out d problem
    "Thanks and regards"
    Jonty

    Increasing the contrast springs to mind.
    When used to extremes it is sometimes called
    'cartoonising'
    Suppose your image was in 16 colors, you could
    reasonably safely assume at least two are red, two
    are blue, two are yellow ect.
    With regards an algorithm you are looking to 'round
    off' the color values to (my suggestion only) the
    nearest 64 or even the nearest 127...
    Bamkinjust be careful of that ORANGE color. Orange is a tricky color to define in either RGB or HSB, and is very similar to red and yellow. A little change in either direction makes it difficult to distinguish from one or the other.
    my thought would be to try to force your image to only six colors. Then those colors (it wouldn't really matter if they were accurate, as long as they are correctly distinguished) would be easy to identify.
    - Adam

  • Image Orientation/Rotation Problem in Lightroom 3.2 Final

    This is a continuation of my previous post regarding this same problem in 3.2RC. It's still happening in the Final version of Lightroom 3.2.
    THE PROBLEM
    Image orientation is not working properly in Lightroom 3.2. This affects newly imported images and images that were already in my Lightroom database -  and which have been in the database since Version 1.
    Here's a screen capture showing the strange displays I'm seeing in  Lightroom's grid mode:
    Notice the odd angle of the image. When I use the Rotate Photo Left tool, the display looks like this sometimes. After a second or so, it will snap to either a vertical or horizontal orientation by itself but rarely gives me the 90-degree rotation this tool should give. The image may flip 90-degrees or 180-degrees, there's no way to tell.
    When I view the image in Loupe view or on my second monitor, the orientation shown in Grid view does not match that displayed in Loupe Vew. For this particular image, Grid view currently shows it as correctly orientated as a horizontal while Loupe view shows it rotated 90-degrees to the right. Shouldn't they match?
    BACKGROUND
    I never had a problem with image orientation in any preveious version of Lightroom prior to Lightroom 3.2RC and 3.2 Final. So, it seems to be a bug in 3.2. I'm still using the same computer and video card I used with previous versions. My operating system is Windows 7 Home Premium. Both Windows and Lightroom are 64-bit.
    HELP!
    Is anyone else having this problem? How can I solve it?
    Alan
    PhtooCitizen.com

    The size of the catalogue is almost certainly not at play here.
    FWIW, I recall seeing something like this once a long time ago on a Mac, possibly with Lr 3 beta, or Lr 2.x.  It went away with a restart. It almost looks like a threading issue, where a thread is suspended or preempted and then is lost or disconnected from the main UI thread.
    I recall you can just rotate the image again and it will right itself.
    Adobe fist-line support seem to want to use the number of images in the catalogue as some sort of catch-all.  The problem with this is that most of us can demonstrate that there is little correspondence with the number of image IDs in the database and many reported UI artefacts.
    I'd keep raising this with them, and suggesting that the size of the catalogue is probably not at play here. As a tactic, you can ask what the maximum size of a catalogue should be, and if it is raw images or the number of changes to the images and virtual copies that is the problem, and if this can be verified by second- or third-line support.

  • Encoding still image files - quality problems

    The project is almost over, and of course problems are now rearing their ugly heads.
    The .pct files I'm using for the menus seemed to encode just fine last week, with very little noticeable MPEG2 compression. Now however, without any changes to the files, the menus look terrible with blocks and noise all over the place! What the heck happened?
    Here's a before and after comparison screen grab:
    Before: http://www.moonbase9.com/images/apps/dsp/menu_before.png
    After: http://www.moonbase9.com/images/apps/dsp/menu_after.png
    The settings in DSP for MPEG2 encoding are the same for both shots. All my video material is pre-encoded .m2v files and AC3 audio. The only part I'm allowing DSP to encode are the .pct menus.
    I've also tried encoding the .pct files in Compressor and the same thing happens, no matter what quality setting I use.

    Hi There
    Trty deleting the mpegs that DVDSP created for the menus as well as your DVDSP prefs, change the encoding preferences by say 0.5Mbps, let DVDSP encode again see what happens.
    Cheers
    B

  • Colour Profiles on exported images causing major problems

    I've been exporting keynote slides as png's to use in video presentations. The problem is that the png's are saved with colour profiles, which means if I export the images from diferent macs, or even the same mac but with a different monitor attached (therefore a diferent monitor colour profile active), the images have very noticeable colour variations.
    This is a major problem. I exported 1,000 slide transitions to import into Adobe Premiere, then about 500 slide updates that when imported, were in some cases darker or lighter even though I was using the same keynote and original images. I had to create a batch job in Photoshop to open, ignore the stored profile and save the images using a new default colour profile to try and get all the images consistent.
    There needs to be an option in either the Keynote preferences or export options to save exported images without colour profiles.

    There needs to be an option in either the Keynote preferences or export options to save exported images without colour profiles.
    No, there needs to be documentation on the ICC architecture and how ICC profiles are applied. Stripping out embedded ICC profiles will colour manage the objects (images) in the system, but when the images pass outside the system they will not be colour managed any more. In this scenario, either they will have to be rendered as deviceColor by the numbers, without a definition of the colours their colourants should form, or a source ICC profile will have to be assigned by the following system/application.
    I've been exporting keynote slides as png's to use in video presentations. The problem is that the png's are saved with colour profiles, which means if I export the images from diferent macs, or even the same mac but with a different monitor attached (therefore a diferent monitor colour profile active), the images have very noticeable colour variations.
    I could be considered an unconditional bug in Keynote if it embedded the current monitor profile and not the system RGB colour working space profile (: Generic RGB Profile). If indeed Keynote embeds the current monitor profile, it could be considered an unconditional bug in your understanding if you start by stripping the source profiles. You should be doing a profile to profile conversion in order to get into the RGB colour working space you want in Photoshop.
    Sorry, but it helps to have a basic understanding of media independent colour matching (even if the developers don't sometimes -:)).
    /hh

  • Image gallery widget problems

    First of all, I'm pretty new to coding and using CS4 on my Mac. I'm trying to create a simple lightbox gallery. I'm using the Adobe Widget Browser and downloaded Lightbox Gallery Widget. I had to copy/paste all of the coding because for some reason dragging/dropping didn’t work. All of my thumbnails look good, but when I view in Live mode or in a browser, the large image does not appear. All of my images are in the correct folder and linked, but I'm thinking there's a problem with the 'next', 'prev', etc images.  I’m sure it’s something simple I’m missing, but I’m at my wits end. I’ve used the Markup Validation Service and it checks out ok. Here is my site:
    http://www.turtlecell.com/index.html
    I’d appreciate any assistance! Thank you!
    Holly

    Having a similar issue - I had taken some iphoto galleries off my mobile me gallery page but they were still linked to pages published in iWeb.
    When I realized this I opened iWeb and took the gallery widgets out.
    Then went into iPhoto and republished the galleries to mobile me, then back to iWeb and they still showed blank (like the two didn't know about eachother - name of the gallery is still showing in iWeb, but no longer displays photos).
    Next try - delete the widget from iWeb page, delete the mobile me published gallery from iPhoto, setup a new (different name and all) published gallery in iPhoto - works, gallery page in mobile me works, back to iWeb and insert widget menu and the old galleries are still listed, no new galleries are showing up in iWeb now - great.
    So, trying the tricks of shutting down iPhoto, iWeb, logging out of mobile me account in system preferences as well as via safari on me.com - then log back into every thing and start up iWeb again - still no new iPhoto published mobile me galleries showing in the iWeb insert-widget-mobile me menu.
    Any help? Looking for a refresh in iWeb!?

  • LR 3.6 Export to Photoshop CS5 - Images have massive problems.

    Windows 7 x64
    Lightroom 3.6
    Photoshop CS5
    When I use the Export to Photoshop feature (or if I export to PSD or export to TIFF and then open in Photoshop), the images look like this:
    When the original in Lighroom looks like this:
    If I zoom in to 100% the weird artifacting/tearing goes away, but if I zoom out any more than 66%, it gets these weird malformations on the image. I cannot figure out why. It's not the image size since I've worked with 100+ meg PSD files in Photoshop before without this issue. If I export to JPG from LR and then open in Photoshop, it's fine. It just happens with TIFF or PSD. Driving me nuts.
    Anybody have any idea why?
    Thank you all so much.
    Patrick

    That's a typical video card driver problem affecting Photoshop. Update the driver from the manufacturer's site (NVidia or ATI).

  • Need help with Rollover Image cross browser problem

    Hello,
    I am having a cross browser problem with my websites rollover nav links.  The trouble is, while they work perfectly fine in IE8 and IE9, I’ve also attempted to use them through Opera, and they simply don’t work.  They don’t link nor do they do their rollover effect.  And I was trying to figure out what I have done wrong.  Currently the site is not completed, but the first two pages are, the “news” and “about me” pages are currently (as of right now) working.  The address to the site is below.
    http://maxmetal.xsustudios.com/index.html
    I hope that someone can help me with this, if needs be I can put the code for the CSS and HTML into this part if it will save some time for everyone.  Sorry too about the PNG images, I have to change those over to semi-transparent GIF’s yet so the site does take a while to load…
    Hope someone can help me with this!
    PALADIN

    When I disable CSS in my browser, the rollover buttons work just fine.  This tells me your CSS is messed up and you've layered something over your menus which is making them inaccessible to users.
    I noticed you've applied relative positioning to just about everything on your page.  Why?   Default CSS positioning (unspecified or static) is all you need for 98% of layouts.
         Learn CSS positioning in 10 Steps
         http://www.barelyfitz.com/screencast/html-training/css/positioning/
    My advice would be to start over using a pre-built CSS Template with all the divisions and columns you're likely to need for this project.  Below are some good links to get you on the right track.
    For professional CSS Templates that are rock solid & perform well in all browsers, visit Project Seven:
    http://www.projectseven.com/products/index.htm
    Ultimate Multi-Column Layouts
    http://matthewjamestaylor.com/blog/ultimate-multi-column-liquid-layouts-em-and-pixel-width s
    Not Just a Grid CSS Framework
    http://www.notjustagrid.com/demo.asp
    EZ-CSS Templates (watch the screencast to see how it works)
    http://www.ez-css.org/css_templates
    Dreamweaver CSS Templates for beginners
    http://www.adobe.com/devnet/dreamweaver/articles/dreamweaver_custom_templates.html
    New DW Starter Pages
    http://www.adobe.com/devnet/dreamweaver/articles/introducing_new_css_layouts.html
    Good luck with your project!
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

Maybe you are looking for

  • Same system being shown multiple time in Solution for Early Watch Report

    Hi Gurus , I have some satellite system configured to Solution Manager . Today I can see the same system entry multiple time in the Operations: Solution Monitoring -> Early Watch Alert. eg ., I have a system whose SID is ABC , i can see the ABC entry

  • Inserting image in to database !!

    Hi All, I have to insert image in to the database. My image is there in swing object Image. Is there any way to insert that image in to the database. Any body having knowledge on this, Please help. Thanks in advance. Regards, Roja.

  • Hey gurus, req to help me.......

    what do we mean by end user manual and end user training and can any body explain this two concepts in detail and details involved in it.

  • How to open the mobile gallery?

    Hi everybody, I'm doing a project in j2me. In which i need to open the mobile phone gallery and select the file to upload to the server. Please help me how to open the mobile phone gallery. is it possible to open by using fileconnection? Gallery shou

  • Photoshop Elements 12 Problems

    Before I was able to drag one picture into another but now it says that the background was locked so I unlocked it but the problem persisted. Also when I put the picture with the Place option I can not move the picture around that other picture, unle