Results 1 to 4 of 4
  1. #1
    spydevil is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default BufferedImage Problem

    Java Code:
    public class image{
    	JFrame pen = new JFrame();
    	BufferedImage bI;
    	
    	public image() {
    		
    		pen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		pen.setBounds(150, 100, 613, 213);
    		
    		try {
    			URL url = new URL("http://images2.layoutsparks.com/1/56178/castle-stone-window-grey.jpg");
    			bI = ImageIO.read(url.openStream());
    			pen.setVisible(true);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	public void paintComponent(Graphics g){
    		Graphics2D g2 = (Graphics2D)g;
    		g2 = bI.createGraphics();
    		g2.drawImage(bI, null, 0, 0);
    	}
    }

    Why dont work?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: BufferedImage Problem

    What does "don't work" mean?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: BufferedImage Problem

    Recommended reading: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Note carefully which Graphics reference is used for custom painting.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: BufferedImage Problem

    To expand on what Tolls is asking, it's hard to answer questions like "why doesn't this work?" without knowing what's not working about it. We don't know for sure what doesn't work for you- whether it results in a compiler error, a runtime error, an unwanted or unexpected behavior, or something else entirely. And since this isn't an SSCCE, we can't run it to see for ourselves.

    In this case it's fairly obvious what you're doing wrong, so I highly recommend taking Darryl's advice. But in the future, try to ask a specific technical question (and provide an SSCCE) instead of asking general questions. It's much easier to answer "I was expecting this code to do XYZ, but it does ABC instead, what's going on?" than it is to answer questions like "why doesn't this work?" with no other information.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. BufferedImage problem
    By Jedan_covik in forum New To Java
    Replies: 5
    Last Post: 08-31-2012, 06:13 PM
  2. BufferedImage not going to GC
    By vspin in forum New To Java
    Replies: 11
    Last Post: 07-03-2012, 09:42 AM
  3. Problem Drawing Grid with BufferedImage.
    By Shikatsu in forum Java 2D
    Replies: 10
    Last Post: 11-26-2011, 12:01 AM
  4. Problem with JFileChooser and BufferedImage Class
    By toro1984 in forum AWT / Swing
    Replies: 3
    Last Post: 11-03-2010, 10:09 AM
  5. free memory of bufferedimage problem
    By mr_empty in forum Java 2D
    Replies: 2
    Last Post: 01-17-2010, 06:27 PM

Posting Permissions

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