Sign in to follow this  

Java rotating image problem

Recommended Posts

Does anyone know how to rotate a regular image in java? Im tryin to rotate this object 45 degrese. Well if ya know i'd like to kow. If ya need more info i'll give ya more info. I just need to know how to rotate an image 45 degrese. Heres what I mean //i have an image named meteor Image meteor //later i get image meteor = getImage(getDocumentBase(),"m.jpg"); //i have a meteorengine method that is called and repaints the applet every time this becomes true if(m_x <= -10){MeteorEngine();} //if the meteor is off of screen go to meteor method. //meteorengine method public void MeteorEngine() { m_x = (int)(Math.random()*500 + 500); m_xy = (int)(Math.random()*500); //sets meteor x&y at random, plus the x a random number + 500 which is the width of the game screen so it just doesn't pop outta know where. //here is where I want to rotate the image but don't know how. meteor.rotate(45); //I know this is legal with a buffered image, so how do i convert to bufferd image and will it ruin my buffered image or not, or how can i do this to a regular image? } I appreciate all the effort, reading, support, and help upfront. Thanks, c.s. finch

Share this post

Link to post
Share on other sites
I came up with this directly from this website.

Google more.

int buffer[] = new int[32 * 32];
int rotate[] = new int[32 * 32];

PixelGrabber grabber = new PixelGrabber(_METEOR_IMG_, 0, 0, 32, 32,
buffer, 0, 32);

for(int y = 0; y < 32; y++) {
for(int x = 0; x < 32; x++) {
rotate[((32-x-1)*32)+y] = buffer[(y*32)+x];
_NEW_METEOR_IMG_= createImage(new MemoryImageSource(32, 32, rotate,
0, 32));

Edit: Whoops that only does 90 degrees. But scroll down on the site and it demonstrates rotating in 5 degree increment. P.S. This was my google search "java image rotate," first result.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this