Advertisement Jump to content
Sign in to follow this  
Coder In Action III

BackBufferedImage/Rotation Images

This topic is 4678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

/*Sorry, just noticed that this is supposed to be 'API un-Specific*/ Ok, quick question; I want to rotate 2D images for my game. As you probably know doing this real time is slow. So in order to overcome that problem, I want to take ImageA, rotate it, and 'copy' it to ImageB. There will be an array of 'ImageBs' wich will contain an ImageA rotated by x degrees. Im am doing this in JAVA and I just don't know what to do; here is my code, I have successfully 'copied' ImageA to ImageB, but when I rotate and then copy... well the screen blinks from black to grey and then turns grey.. I don't know what is the matter with what I am doing (Oh and this is a small test file, my actual game has over a dozen files; ScreenManager is basically a class that gives me a graphical context to the screen and handles some backbuffering for me. import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.*; import javax.swing.*; import java.awt.geom.AffineTransform; public class hard { public static void main(String [] args) { AffineTransform rTrans = new AffineTransform(); rTrans.rotate(90); BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR );/*possible problem here, I just don't know what type of image my .png is*/ Image im = loadImage("Images/38.png"); Graphics2D g2 = image.createGraphics(); System.out.println(im); g2.drawImage(im,rTrans,null);//This doesn't WORK /*If I replace the previous line with: g2.drawImage(im, 0,0,null); it works just fine, and I have thought about it 'rotating off the screen' but nope, and it isn't a null value either */ ScreenManager screen = new ScreenManager(); while(true){ Graphics2D g = screen.getGraphics(); screen.cls(); System.out.println(image); g.drawImage(image, 100,100, null); g.dispose(); screen.update(); //System.exit(1); } } protected static Image loadImage(String fileName) { return new ImageIcon(fileName).getImage(); } } [Edited by - Coder In Action III on March 29, 2006 7:56:42 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!