Skip to main content

Blitting one BufferedImage onto another.

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
Ploppz
Offline
Joined: 2013-03-21

Hey!
I just found this forum, it look supernice! :D

I am learning Java and to start I am making a GUI system and pong game.

When I am rendering my buttons, they are simply just some white text on black background. When they are hovered/pressed I just simply want to have a colored pixel outline. So before drawing the buttons to the main BufferedImage, I need to store each one in a temporary BufferedImage, apply the outline effect (that I made) to that BufferedImage, and then copying the temporary BufferedImage to the main one (the canvas).

So I need help to copy one buffered image onto another (giving x and y position as parameters of course)!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
anthony_p
Offline
Joined: 2006-07-24

Hi,

1. Use BufferedImage.getGraphics() and Graphics.drawIamge() to blit an image.

2. People also use XOR composite to draw outlines.

3. Why not use a UI toolkit (Swing) for buttons and other controls?

4. Java2D/Swing are so old. Have you considered learning JavaFX instead? Start here: http://www.oracle.com/technetwork/java/javafx/documentation/index.html

--
best regards,
Anthony

Ploppz
Offline
Joined: 2013-03-21

Hello, thanks for reply!

getGraphics and drawImage did the job :D

Swing buttons look boring and don't fit in a game. I want to make it myself. JavaFX looks better than swing, but for this small project I will just use the built in stuff.

I have also been recommended game libraries like lwjgl and Slick. I am not sure yet though. I like figuring out things myself. Building my own libraries and systems. I like learning a lot. And I find what I learn from building my own libraries more valuable than learning a new library. Also it allows me to adapt my libraries to my code style and not the other way around.

I am not very experienced with external libraries anyway so I don't know if there's a lot I miss from not using those.

anthony_p
Offline
Joined: 2006-07-24

You're welcome.

I can't really comment on 3rd-party libraries since I've never used them myself.

However, speaking of FX - it is not an external library whatsoever. It's bundled with JDK starting with 7u6 IIRC and is a part of the platform. So if later you decide to switch over to using JavaFX APIs - feel free to do so. There's no external dependencies associated with it (other than the minimum JDK version).