Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Cannot Read Image

    Hello would some one be able to help? my program doesnseem t be able to read the image
    Java Code:
    import java.awt.*; 
    import java.awt.image.BufferedImage;
    import java.io.*;
    
    import javax.imageio.*;
    import javax.swing.JFrame; 
    
    /** 
     * Main class for the game 
     */ 
    public class Core extends JFrame 
    {        
    	BufferedImage backbuffer;
    	BufferedImage img;
            public static void main(String[] args) 
            { 
                new Core(); 
                //game.run(); 
                //System.exit(0);   
            } 
            public Core(){
                setTitle("Game Tutorial"); 
                setSize(600, 600); 
                setResizable(false); 
                setDefaultCloseOperation(EXIT_ON_CLOSE); 
                setVisible(true); 
                backbuffer = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB); 
            	try {
            	    img = ImageIO.read(new File("UTD.bmp"));
            	} catch (IOException e){}
            }
    
            public void paint() 
            { 
            	Graphics g = getGraphics();
            	Graphics g2d = (Graphics2D) g;
            	Graphics bbg = backbuffer.getGraphics(); 
            	bbg.setColor(Color.WHITE);
            	bbg.fillRect(0, 0, 600, 600);
            	g.drawImage(backbuffer, 0, 0, this);
            	g2d.drawImage(img, 0, 0, this);
            } 
    }
    This is the coding of my program.
    Cannot Read Image-no-picture.jpg
    Thanks fo trying to help
    Last edited by YaFedImYaEatIm; 08-13-2012 at 01:53 PM. Reason: Accidentaly violated forum rules - added picture

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

    Default Re: Cannot Read Image

    Hello. Consider telling us more about your problem, such as any and all error messages, and what does happen when this code is run. Also, where are the images relative to the user directory? You can find the user dir by running:

    Java Code:
    // code not tested yet
    System.out.println(System.getProperty("user.dir"));

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Cannot Read Image

    Following on a bit from the previous, try:

    Java Code:
    try {
        File file = new File("UTD.bmp");
        System.out.println("Reading the file at " + file.getAbsolutePath());
        img = ImageIO.read(file);
    } catch (IOException e){
        e.printStackTrace();
    }
    getAbsolutePath() will tell you (and us) where exactly you are looking for the file. And printStackTrace() will provide useful information when things go wrong. Both techniques (or something similar) are common.

  4. #4
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: Cannot Read Image

    Thank for you support guys have actually found a solution by stuffing around with the program which is
    Java Code:
    import java.awt.*; 
    import java.awt.image.BufferedImage;
    import java.io.*;
    
    import javax.imageio.*;
    import javax.swing.JFrame; 
    
    public class Core extends JFrame 
    {        
    	BufferedImage backbuffer;
    	BufferedImage img;
            public static void main(String[] args) 
            { 
                new Core(); 
                //game.run(); 
                //System.exit(0);   
            } 
            public Core(){
                setTitle("Game Tutorial"); 
                setSize(600, 600); 
                setResizable(false); 
                setDefaultCloseOperation(EXIT_ON_CLOSE); 
                setVisible(true); 
                backbuffer = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB); 
            	try {
            	    img = ImageIO.read(new File("UTD.bmp"));
            	} catch (IOException e){}
            }
    
            public void paint(Graphics g) 
            { 
            	Graphics g2d = (Graphics2D) g;
            	Graphics bbg = backbuffer.getGraphics(); 
            	bbg.setColor(Color.WHITE);
            	bbg.fillRect(0, 0, 600, 600);
            	g.drawImage(backbuffer, 0, 0, this);
            	g2d.drawImage(img, 0, 0, this);
            } 
    }
    Works perfectly fine now thanks again for you kindness and tolerance with my violation.
    Last edited by YaFedImYaEatIm; 08-13-2012 at 02:23 PM.

Similar Threads

  1. read tiff image header
    By mr_empty in forum Java 2D
    Replies: 0
    Last Post: 12-23-2009, 05:08 AM
  2. read image without bufferedimage
    By mr_empty in forum Java 2D
    Replies: 5
    Last Post: 12-23-2009, 04:59 AM
  3. Read and draw a local image.
    By ichwar in forum New To Java
    Replies: 1
    Last Post: 07-27-2009, 03:02 PM
  4. how to read an image and display
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2009, 01:43 PM
  5. How to read an image in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:30 AM

Tags for this Thread

Posting Permissions

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