Results 1 to 7 of 7
  1. #1
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Angry to display image

    hi frnds,
    i m trying to display multiple images on a single frame using BufferedImage class in java.The thing is that i m able to display single image on a single frame but not more than one image on the same frame.i have tried with this

    public void paint(Graphics g)
    {
    g2=(Graphics2D)g;
    AffineTransform at = AffineTransform.getScaleInstance(currentRate, currentRate);
    String [] files ={ "D:\\rnd\\testImages\\test.jpg","D:\\rnd\\testImag es\\test1.jpg" };

    BufferedImage[] images = new BufferedImage[files.length];
    int i;
    for(i = 0; i < files.length; i++)
    {
    try
    {

    images[i] = ImageIO.read(new File(files[i]));
    System.out.println("i m here");
    }


    catch(Exception e)
    {
    System.out.println("Cant find file " +files[i]);
    }
    }


    The code is not generating any error msg or exception.its just displaying blank frame can anyone help me out to do this as soon as possible

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    You haven't posted any code that does any painting of any images. And why are you doing your file IO in your paint method? And why are you using paint() instead of paintComponent()?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    public MultiImageg()
    {
    String [] files ={ "D:\\rnd\\testImages\\test.jpg","D:\\rnd\\testImag es\\test1.jpg"};

    BufferedImage[] images = new BufferedImage[files.length];
    int i;
    for(i = 0; i < files.length; i++)
    {
    try
    {

    images[i] = ImageIO.read(new File(files[i]));
    System.out.println("i m here");
    }


    catch(Exception e)
    {
    System.out.println("Cant find file " +files[i]);
    }
    }
    }

    public void paint(Graphics g)
    {
    System.out.println("i have reached here");
    g2=(Graphics2D)g;
    //g3=(Graphics2D)g;

    AffineTransform at = AffineTransform.getScaleInstance(currentRate, currentRate);
    //g2.drawImage(img, at,null);


    for( i=0;i<images[i].length;i++)
    {
    //g2=images.createGraphics();
    g2.drawImage(images[i],20,20,null);
    g2.drawImage(images[i],at,null);

    }
    }

  4. #4
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    Thanx for ur reply.I have resent u the code.This is what i was trying to do plz do help me out to display multiple images and reply as soon as possible.waitng for ur reply

  5. #5
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    further i have just created a class that creates an object of frame and calls the above MultiImageg constructor and adds its object to the frame.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Double posted (reported the other thread)
    image display

    db

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. How to display image in JEditorPane
    By usccar in forum New To Java
    Replies: 1
    Last Post: 12-10-2009, 06:34 AM
  2. how to read an image and display
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2009, 12:43 PM
  3. How to display image ?
    By Birkoff in forum AWT / Swing
    Replies: 7
    Last Post: 06-09-2008, 07:58 AM
  4. How to display an image in JApplet
    By fred in forum Java Applets
    Replies: 1
    Last Post: 07-24-2007, 02:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •