Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


[java] image rotation


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   -  Reputation: 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

Sponsor:

#2 Jim_Ross   Members   -  Reputation: 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   -  Reputation: 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   -  Reputation: 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   -  Reputation: 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   -  Reputation: 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   -  Reputation: 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.



PARTNERS