Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

[java] image rotation

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 virtuosity   Members   

122
Like
Likes
Like

Posted 08 July 2000 - 06:11 PM

I''ve been trying to rotate a bitmap using a SpinFilter class available on the webpage http://hplasim2.univ-lyon1.fr/c.ray/bks/java/htm/ch51.htm but I haven''t been able to display the rotated image. The code I used is as follows: Image image = getImage(getDocumentBase(),"wraith.gif"); Image filteredImage = createImage(new FilteredImageSource(image.getSource(),new SpinFilter(90.0)); I can draw the unfiltered original image with no problems but when I try to draw filteredImage, nothing is drawn. What am I doing wrong? Thanks in advance, virtuosity

#2 Jim_Ross   Members   

122
Like
Likes
Like

Posted 09 July 2000 - 10:34 AM

It''s been my recent experience with images that if it comes out blank, something along the way is null. Try making each variable individually and doing
System.out.println(var);
to see if it''s null. For example:

ImageProducer producer = image.getSource();
System.out.println(producer);
...
Image filtered = Toolkit.getDefaultTooklit().createImage(...);

Also, if those two lines are right next to each other in the source, then it''s probably that the image has not yet been fully loaded, you can use a media tracker to wait untill it''s loaded, but if you only have one image you might try

while ( image.getHeight(null) == -1) ;

before trying to get it''s source pixels. While an Image is loading it''s height & width are -1.

#3 ManaSink   Members   

122
Like
Likes
Like

Posted 10 July 2000 - 01:05 AM

quote:
Original post by Jim_Ross

Also, if those two lines are right next to each other in the source, then it''s probably that the image has not yet been fully loaded, you can use a media tracker to wait untill it''s loaded,


I second this. My gut feeling is your image probably hasn''t been loaded yet.

ManaSink




#4 virtuosity   Members   

122
Like
Likes
Like

Posted 10 July 2000 - 10:26 AM

I modified my code as follows and I was able to draw the image:
Image image = getImage(getDocumentBase(),"wraith.gif");
while ( image.getHeight(null) == -1) ;
ImageProducer producer = image.getSource();
ImageFilter filter = new SpinFilter(Math.PI/2);
ImageProducer filterProducer = new FilteredImageSource(producer,filter);
Image filteredImage = createImage(filterProducer);

I think the key thing was to make each of the variables individually. If I don''t wait for the image to load, I can still draw the image, albeit with a small delay. Thanks a lot for the suggestions Jim_Ross.

#5 virtuosity   Members   

122
Like
Likes
Like

Posted 10 July 2000 - 11:26 AM

Now that I can rotate images and draw them, I have another problem. What I''ve been attempting to do is to rotate an image a full 360 degrees in an animation sequence. The problem is that when I rotate the image, it seems that the center of the image doesn''t remain in the same place even though I''m drawing all the rotated images in the same location. This results in a jerky rotation animation because the center of rotation seems to jump all over the place. How can I rotate an image smoothly?

Thanks,
virtuosity

#6 buh   Members   

122
Like
Likes
Like

Posted 11 July 2000 - 10:18 AM

I think you''ll have to change the top left corner coords every frame. For example, if the new image is 10 pixels wider than the original one then you subtract 5 from the x coord.


#7 SteveMeister   Members   

122
Like
Likes
Like

Posted 11 July 2000 - 11:34 AM

Or use Java2D and apply a rotation transform before painting the image...




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.