Load jpg in image object

Hi, i'm trying to create an image object from a jpg file:
public static void main(String[] args)
Image img;
Toolkit t;
t = Toolkit.getDefaultToolkit();
img = t.getImage("C:\\Documents and Settings\\m.lipreri\\Desktop\\ciao.jpg");
System.out.println("img: "+img.toString());
Frame f = new Frame("Es1_Im");
ImageFrame IM = new ImageFrame(f,img);
IM.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
IM.setSize(500,400);
IM.setVisible(true);
class ImageFrame extends Frame{
Frame f;
Image im;
//costruttore
ImageFrame(Frame f,Image im){
this.f = f;
this.im = im;
public void paint(Graphics g){
g.drawImage(im,0,0,this);
}but this code doesn't show me anithing in the applet, the image path is right, i've tried to past the path in my browser and i can see the image.
thnx

Images get loaded asynchronously, so the image
probably isn't loaded completely when you try to
display it. See java.awt.MediaTracker or use
javax.swing.ImageIcon for loading.I could be wrong, but isn't that the ancient way of doing it? I haven't used MediaTracker in ages. Just use ImageIcon. It's the easist way I know to work with images.

Similar Messages

  • How to load a background Image on a JDialog object

    Hi All, Actually i am new to java programing and i am stuck in this problem. I am developing a java application which is dialog based (using JDialog objects) and i want to load a background image on my dialog. I hope this could be done and i really appreciate your help because i must deliver this project and this is a user interface requirement.

    Try something along the lines of this: Create a new class called BackgroundImagePanel and have it extend JPanel.
    Have an attribute in the class for your image, and a method to set it.
    Override isOpaque() to return true.
    Override the paintComponenet method as such:
    public void paintComponent (Graphics g) {
    super.paintComponent(g);
    if( image == null ) return;
    Icon icon = new ImageIcon(image);
    icon.paintIcon(this, g, x, y);
    Add this panel to your JDialog and then add other component to this panel.
    You might have to tweak this a bit, but it should get you close...
    Bill

  • Converting a image file (JPG or BMP or any other) to an Image object

    Hello, does anyone have an idea of how I could convert a image file (JPG, BMP, GIF or any other) or even a Corel Draw (.CDR) file to a java Image object?
    Thanks in advance
    Wilson

    Demo:
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class ImageResized {
        public static void main(String[] args) throws IOException {
            URL url = new URL("http://today.java.net/jag/bio/JagHeadshot.jpg");
            BufferedImage image = ImageIO.read(url);
            Icon icon = new ImageIcon(image);
            JLabel label = new JLabel(icon);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Outputting an Image object to jpg or png

    Hello,
    I have an Image object in my code that is output from another java object. The other java object is from a libarary of GIS classes known as JLOOX.
    Anyway, I have an Image stored in the Image object but want to output it to a file. I was looking at the Java Almanac and saw a page http://javaalmanac.com/egs/javax.imageio/Graphic2File.html However, this uses a BufferedImage object.
    Is there anything I can do with the Image object to output to a file? Can I convert it to a BufferedImage somehow?

    BufferedImage b = new BufferedImage(
    source.getWidth(), source.getHeight(),
    BufferedImage.TYPE_INT_ARGB  );
    b.getGraphics().drawImage( 0, 0, source, null );
    ImageIO.write( b, "png" );Thanks, but I have an Image object. How do I write the Image object to ImageIo.write?

  • How to load a PNG image from a location in CF card

    Hi,
    I am using WTK 2.5.2. I wanted to load a PNG image to Image object. The image is loaded when I have it in the classes folder. But I want to select different image from a different location. If I try to open an Image to createImage(String) from a different location, I get IOException.
    Please help me.
    Thanks
    Deekshit M

    I got the answer, I should be using Image.createImage(InputStream) API. It works fine.
    Thanks
    DM

  • Loading only last image

    This code is loading the xml correctly, populating the mainClipArray correctly, but only adding the last image to the stage.
    I think it is not waiting for completeClipLoad() to complete.  I tried removing :void from the function to see if waiting for a return would do it, but no luck.
    Any ideas?
    CODE:
    var myXML:XML;
    var xmlLoader:URLLoader = new URLLoader();
    var mainClipArray:Array = [];
    var counter:int = 0;
    var myLoader:Loader = new Loader();
    xmlLoader.load(new URLRequest("portfolio.xml"));
    xmlLoader.addEventListener(Event.COMPLETE, completeXMLLoad);
    function completeXMLLoad(e:Event):void{
        myXML = XML(e.target.data);
        var len:int = myXML.portfolio.unit.length();
        for(var i:int = 0; i<len; i++){
            counter = i;
            mainClipArray[i] = new pane();
            //Load small image
            var smallfilename = myXML.portfolio.unit[i].small.filename;
            myLoader.load(new URLRequest(smallfilename));
            myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeClipLoad);
            mainClipArray[i].x = i * 15;
            addChild(mainClipArray[i]);
    function completeClipLoad(e:Event):void{
        trace("made it in");
        mainClipArray[counter].addChild(myLoader);
        trace("added child");

    Delaying the progress isn't going to help if you still have only one loader.  I would say that you could move the var myLoader:Loader = new Loader(); line inside the loop so that you have a new loader instance for each loading occurence, but then you would also need to adjust the completeClipLoad function to use the event target (e.target) instead of "myLoader".  But that still wouldn't resolve matters completely because you have that counter variable that will be working as fast as the for loop, with the loop likely finishing before the first item gets loaded... and since your completeClipLoad also makes use of that variable, you'll end up with only the last pane object being used.
    If you want to control the order of loading and retain the code in the one place (the other suggestion offered above having the code inside the pane could also be a viable approach), then a better strategy is to to use a programmed loop rather than a for loop, where only one loading occurs at a time and the completion of one loading triggers the next to begin.  Something like (this is just an outline form)...
    counter = 0;
    imgArray;
    function completeXMLLoad(e:Event):void{
         ... // process all the xml into the imgAray
        loadSmallImage(); // start by loading the first image only
    function loadSmallImage(){
         // create loader instance
         // assign load complete listener
         // load imgArray[counter]
    function loadComplete(e:Event) {
         // process the loaded image in a new pane
         // increment counter
         // if counter is < imgArray.length -> loadSmallImage();

  • [Q] loaded jpg is cut off in the middle!!!!

    Hi, I am having troulbe loading an external jpg image
    jpg file is long rectangular shape (width 700px * height
    8000px <possiblely longer>), and around 1.2mb.
    I am loading image with listener (onComplete?: I was using
    someone else's tutorial, sorry for my lact of knowledge)
    Everything worked..tutorial was great..and result was fine
    HOWEVER, when I am loading my own image(which i specified
    above), It seems like only 1/3 of jpg file is loaded.
    (I wantted to make a scrollable image gallery sort of
    thing..showing long portrait images)
    I was wondering is there any external file size limit in
    flash???
    or height(pixel size) limit?? or any other possibly related
    issue that i am not aware of???
    Can someone help me out ?
    Is there any way I can fix it without touching jpg images?
    (last way would be cutting the all jpg images into smaller
    pieces or making images size smaller :'()
    THANK YOU FOR YOUR TIIME ~~

    yes, there's a limit of 2880 pixels in height and width for
    an image.
    to remedy, import your jpg to flash and publish the swf. you
    should be able to load the swf and get around the 2880 limit.
    there are other work-arounds, but that one is the
    easiest.

  • I have a problem with loading the PNG image

    I have a problem with loading the PNG image from site. For ex. go to icefilms com and is starts to load png like crazy CPU is huge and you can not shut down Firefox at least a minute. This is not just in this site but whit any one whit lots of pictures.
    Image from firefox: Picture [http://img836.imageshack.us/img836/9910/7312011103147pm.jpg 1] [http://img28.imageshack.us/img28/8505/7312011103249pm.jpg 2] [http://img706.imageshack.us/img706/5615/7312011103348pm.jpg 3 ][http://img827.imageshack.us/img827/8483/7312011103533pm.jpg 4]
    This is my Task Manager [http://img217.imageshack.us/img217/5715/7312011103621pm.jpg 1]
    - I try safe mode, same thing
    -All addons and plugins are ok
    Any idea why is this so big problem.

    i did both of them, but still the while sending the mail the diolog box is not showing up and also the spelling and grammer does not do the spelling check. 
    This problem just started for about 3 to 4 days now.  earlier it was working normally.

  • Flash actionscript loads jpg files, no png or gif

    Hi, I'm using this script to load png files, but it does not
    load them, it loads jpgs. It is being pulled from an xml file. I
    have also tried gifs and that does not work. I need to put images
    that have transparency. I can not find any refrence to jpg in the
    code or anything like that. Any ideas would be helpful.
    code:
    Thanks,
    Josh

    Hi, I'm using this script to load png files, but it does not
    load them, it loads jpgs. It is being pulled from an xml file. I
    have also tried gifs and that does not work. I need to put images
    that have transparency. I can not find any refrence to jpg in the
    code or anything like that. Any ideas would be helpful.
    code:
    Thanks,
    Josh

  • Optimization on Load Time (Large Images and Sounds)

    Hi,
    I have an all flash website that works by having each portion of it to load and unload in the center of a frame based off the navigation chosen.  Load times on everything but one part of my site are ok.
    The dimensions of the part inside the frame are 968x674.  I know that's relatively large for a flash file, but that can't be changed at this point.
    Within the page there are objects that come up when you find an item on the screen.  Its a dialog box and it shows text, an image, and has a voice over that reads what the text says.  After you're done looking at it, there is an x-button to dismiss the window.  There are 15 of these and they are exported to the actionscript.  I add them in the actionscript via addChild.  I figured this is a huge spot that could be reconfigured, but I'm not sure if it would make much a difference.
    The other huge thing is there is a ton on the screen.  It starts you off in an environment, and when you click 3 different sections, it zooms into that portion allowing you to look for the items you're trying to find.
    There is also a man that talks and animates in the beginning and at the end.  We are planning on taking out the end part and putting a text box up.
    Here is the website..  its a propane safety site for kids.  I know its kind of a weird idea, but it works and people seem to like it.
    www.propanekids.com
    The two parts of the site we are trying to optimize is the main menu when you first are at the site, and the "Explore" section.  (Just click on the cloud on the front page.
    If someone could take the time to give me some new ideas of how I can get these loading times down, I would greatly appreciate it!
    Thanks

    Ok, who ever posted this message is hacking me  and i can't believe you guys are helping
    Date: Thu, 27 Jan 2011 11:07:28 -0700
    From: [email protected]
    To: [email protected]
    Subject: Optimization on Load Time (Large Images and Sounds)
    Hi,
    I have an all flash website that works by having each portion of it to load and unload in the center of a frame based off the navigation chosen.  Load times on everything but one part of my site are ok.
    The dimensions of the part inside the frame are 968x674.  I know that's relatively large for a flash file, but that can't be changed at this point.
    Within the page there are objects that come up when you find an item on the screen.  Its a dialog box and it shows text, an image, and has a voice over that reads what the text says.  After you're done looking at it, there is an x-button to dismiss the window.  There are 15 of these and they are exported to the actionscript.  I add them in the actionscript via addChild.  I figured this is a huge spot that could be reconfigured, but I'm not sure if it would make much a difference.
    The other huge thing is there is a ton on the screen.  It starts you off in an environment, and when you click 3 different sections, it zooms into that portion allowing you to look for the items you're trying to find.
    There is also a man that talks and animates in the beginning and at the end.  We are planning on taking out the end part and putting a text box up.
    Here is the website..  its a propane safety site for kids.  I know its kind of a weird idea, but it works and people seem to like it.
    http://www.propanekids.com
    The two parts of the site we are trying to optimize is the main menu when you first are at the site, and the "Explore" section.  (Just click on the cloud on the front page.
    If someone could take the time to give me some new ideas of how I can get these loading times down, I would greatly appreciate it!
    Thanks
    >

  • Converting JPanels as image objects

    hi,
    i am having problem in converting a JPanel object which consits of some
    JLabels and images into a Image Object. Actually i want to save the JPanel as
    a jpg file which i will do with jped encoder.
    so please help me in converting this JPanel to image object

    assuming the panel is showing.... (if not, you might need to user getPreferredSize() and setVisible before paint()).
    Dimension size = panel.getSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    comp.paint(g2d);

  • Save an Image object into a XML text document

    ello:
    I have a problem with saving an image. I need to encapsulate it into two XML tags:
    <Image> xxxxxx </Image>
    The "xxxx" must be a String that represents my Image object.
    In J2ME I haven't serialization, and all the examples about "manual serialization" works with primitive types :(
    I've already read that I can do .getRGB() over my Image object, and obtain an array of int, wich represent each pixel. Ok, I can transform the array into a String, and write it in my XML text document, but later: how I obtain my array from that String?
    Thak you very much

    private Image img;
    byte rgb[] = null;
    private rgbLength; // get lenth of your string
    rgb = new byte(rgbLength);
    rgb = ... //load data from string to this array
    img = createRGBImage(rgb, int width, int height, false) ;You must know length of your string and must encapsulate in to XML width and height of this image;

  • URGENT : Please HELP : Loading a first image too slow

    Hello,
    I want to load an image to save it just before in a JPG format so as to obtain finally a byte[] array of this JPG image result.
    So, to do it, I tried to load my Image from different ways but I have always a strange comportement... My problem come from the reading :
    First, I use the imageio classes...
    FileImageInputStream fiis = new FileImageInputStream(file);
    BufferedImage input = ImageIO.read(fiis);
    And then, I use the oldest method :
    Image image = new ImageIcon(file.getAbsolutePath()).getImage();
    BufferedImage input = new BufferedImage(image.getWidth(panel), image.getHeight(panel),BufferedImage.TYPE_INT_RGB);
    and also :
    Image image = new ImageIcon(file.getAbsolutePath()).getImage();
    BufferedImage input = toBufferedImage(picture);
    But finally, I understood my problem is that the first time I load an image (no matter the format, JPG, BMP, TIFF... or other) the loading phase is very slow and lasts at least 30 sec. But then, every loading that I do will gonna be really fast. (No more than 1 sec.) It's look like if the first time there was a kind of dinamical alocation or something like that.... but I tried to find some configuration parameters to set it... But without success. :-(
    If someone could have an idea to suggest me... it would help me very much.
    Thanks in advance for your help,
    Anthony

    Please someone can help me ?!? A suggestion ?
    I have tried today one more time to resolve this issue... but without success... Anything I do with the loading of an image... by imageio or other ways... it's still the same problem... the first time I load an image, it takes me 40 - 50 sec to load it and after this first load, it is very fast with others... and with every formats. It's not a question of format but of memory allocation, I think... but I'm not sure...
    PRECISION : I work with an applet, is there something to configurate to allocate some memories or another thing ?!?
    Thanks in advance for your help, I really need it just right now... I have to finish this job extremly fast !!!
    Regards,
    Anthony

  • How to load svg (vector) image dinamicaly.

    Hallo!
    I tryed to load dinamicaly an image svg (.ai) into flash but I can't.
    At my level:
    1) I know that flash can't import .svg file but it is possible convert svg in Adobe ilustrator .ai file;
    2) I can import .ai file in flash with no problem;
    3) I can load dinamicaly external  .jpg file with no problem;
    If I try to load dinamicaly  .ai file in the same way that I use to load  .jpg file I get this message:
    Error #2044: Unhandled ioError:. text=Error #2124: Loaded file is an unknown type. URL: file: .....
    Is there any way to solve this problem?
    Can someone help me?
    Thank you.

    you can use the urlloader class to load the svg but it won't display an image until you parse the xml, Using SVG as a level design format - Zeh Fernando

  • Problem loading vector EPS images

    Hello All-
    I'm having trouble loading vector EPS files (created in Adobe Illustrator CS2) in the data manager (version 5.5.34.46). I have Photoshop CS2 installed and have run the registry compatibility update. When I select the image to add to my data group, Photoshop launches (usually..) to load the preview image but when I say OK, I get one of the following errors:
    1. Illegal value for parameter (within Data Manager)
    2. Unspecified error (within Data Manager)
    3. Microsoft Visual C++ Runtime error (within Data Manager)
    4. Virtual function call failed (within Photoshop)
    I am able to load TIF images although the preview images do not display correctly but I do not want to rasterize my existing vector EPS files.
    After setting the images to RGB color space, I was able to do 2 or 3 EPS imports but it took several attempts and has since not functioned at all. The properties on these files show that they are in fact vector and they work downstream in Publisher and InDesign. This is how I'd like them all to work.
    Any suggestions on how to make this work? Are vector EPS files supported?
    Thanks
    Tim

    Tim-
    Before upgrading to the latest hotfix, I did get a couple vector EPS files to load, and the preview did exist in Data Manager and Publisher. Trouble was, I couldn't consistently load the images without errors. Now I can load the images, but lost the preview. For the time being, this is the lesser of 2 evils.
    I do not have any variants defined at this point so I can verify that linked images do NOT get published to InDesign (unless there is another setting I haven't found to force MDM to use Originals).
    All of the raster graphics I tried (TIF & JPG) work just fine in Publisher and InDesign but as you probably know, vector graphics are the smaller and produce better results for DTP applications so they are preferred, if the choice is available.
    If you're going to load SP05 right away, please post any findings that relate to these issues.
    Thanks for your help.
    Tim

Maybe you are looking for