-
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?
-
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.
-
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.
-
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.
-
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.
-
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
-
By Irina in forum ASP.NET
Replies: 0
Last Post: 11-29-2002, 10:47 PM
-
Replies: 0
Last Post: 12-13-2001, 12:06 PM
-
By Roseta in forum VB Classic
Replies: 0
Last Post: 11-14-2001, 03:24 AM
-
By Ayman in forum VB Classic
Replies: 0
Last Post: 04-03-2000, 01:08 AM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks