BufferedImage Problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: BufferedImage Problem

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    9

    BufferedImage Problem

    I'm trying to draw an Image to a BufferedImage using a Graphics2D object from the createGraphics() method. My code is shown below:

    BufferedImage myImage = new BufferedImage(17*32, 12*32, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = myImage.createGraphics();
    Image currImage = app.getImage(app.getCodeBase(), "tile.png");
    g2d.drawImage(currImage, 5, 5, app);

    app is an Applet object passed in through the constructer in an earlier segment of code. When I run the applet it doesn't show the image. I've tried drawing rectangles before and after the image loading/displaying, and the rectangles show up but without the image. I tried loading the image in my applet class and the image loaded. What am I doing wrong?

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    tried
    drawImage(currImage, 5, 5, null) ?
    by the way: it could be, that loading the image is not finished, when you paint it.
    for such cases you have to use the mediatracker, which will wait for the image to be loaded before it continues.

  3. #3
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    and also: you paint the image on the buffered image and not on the applet.
    you will have to paint your image on the applets graphics object, eg in the paint(Graphics g) method of the applet:
    ((Graphics2D)g).drawImage(currImage, 5, 5, null)
    and not on a seperately created buffered image.

  4. #4
    Join Date
    Jun 2006
    Posts
    9
    Well I need to get a bunch of Images onto a BufferedImage later, but right now I'm just trying to get it to draw one to get it to work. I tried putting null instead of app and nothing works. I also used a MediaTracker to make it not add the image until it was loaded. None of those worked. Any other ideas?

    Edit: nevermind, found that none of my images were loading for some reason.
    Last edited by bobthesmiley; 06-09-2006 at 10:39 AM.

  5. #5
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    you have to paint your buffered image onto the graphics of the applet. as far as can see, you paint everything on the buffered image, but not the buffered image on the applet.

  6. #6
    Join Date
    Jun 2006
    Posts
    9
    I already had a method to paint the buffered image. It takes in a Graphics object and paints the buffered image to that graphics object. I just didn't include it because I felt it was unnecessary to. Also, I check how many images had loaded during each frame and it keeps saying 0 have loaded.

    Edit: figured it out. I forgot to make the mediatracker check all the images every frame.
    Last edited by bobthesmiley; 06-09-2006 at 11:12 AM.

Similar Threads

  1. Problem with Search
    By Irina in forum ASP.NET
    Replies: 0
    Last Post: 11-29-2002, 10:47 PM
  2. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  3. a problem with font and language
    By Roseta in forum VB Classic
    Replies: 0
    Last Post: 11-14-2001, 03:24 AM
  4. Arabic problem view
    By Ayman in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 01:08 AM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 06:48 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center