Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Turning images around the clock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Turning images around the clock" Watch "Turning images around the clock" New topic
Author

Turning images around the clock

Kari Nordmann
Ranch Hand

Joined: Feb 12, 2007
Posts: 38
I want to turn several images around in different directions, like an image of an arrow turning against your cursor.
To be more exact, I want different images of arrows, lightning and others to be shot from different points and then turn against their destination points. So that no arrows etc will be flying backwards...

I will be doing this with several images, so I won't just make every image in several copies...

I've tried searching for it, but I haven't found anything close to my question.
Any ideas?
[ July 15, 2008: Message edited by: Kari Nordmann ]
Sven Goetgeluck
Greenhorn

Joined: Jul 16, 2008
Posts: 14
Hello,

I did this with fonts but it is perfect to do with images

check
http://www.javalobby.org/java/forums/t19387.html

wit regards
sven
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
If you just want to flip the image with respect to its vertical center axis, then you could simply swap the respective pixel values.


Ping & DNS - my free Android networking tools app
Kari Nordmann
Ranch Hand

Joined: Feb 12, 2007
Posts: 38
I tested the example with affine transform, it didn't turn any images around, only moved and resized them... I didn't really understand what the class is ment for either, I dont understand what "affine transform" means

I think it should work fine if I can flip the image to anywhere from 0 to 360 degrees, I'll try to figure that out.
[ July 16, 2008: Message edited by: Kari Nordmann ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
<blockquote>code:
<pre name="code" class="core">
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.event.*;

public class Pointing extends JPanel {
BufferedImage image;
double theta = -Math.PI/4;

Pointing() {
int w = 75, h = 40,
type = BufferedImage.TYPE_INT_ARGB_PRE;
image = new BufferedImage(w,h,type);
Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Path2D.Double path = new Path2D.Double();
path.moveTo(0,10);
path.lineTo(45,10);
path.lineTo(45,0);
path.lineTo(75,20);
path.lineTo(45,40);
path.lineTo(45,30);
path.lineTo(0,30);
path.lineTo(0,10);
g2.setPaint(Color.red);
g2.fill(path);
g2.dispose();
}

protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int w = getWidth();
int h = getHeight();
int r = Math.min(w,h)/3;
double x = w/2 + r*Math.cos(theta);
double y = h/2 + r*Math.sin(theta);
g2.setPaint(Color.blue);
g2.draw(new Line2D.Double(w/2, h/2, x, y));
int iw = image.getWidth();
int ih = image.getHeight();
// Translate the image to the end of the line
// and rotate it from its left end, centered.
AffineTransform at =
AffineTransform.getTranslateInstance(x, y-ih/2);
// Comment-out this next line to see the translation.
at.rotate(theta, 0, ih/2);
g2.drawRenderedImage(image, at);
g2.setPaint(Color.green.darker());
g2.fill(new Ellipse2D.Double(w/2-2, h/2-2, 4, 4));
g2.fill(new Ellipse2D.Double(x-2, y-2, 4, 4));
}

private JSlider getSlider() {
JSlider slider = new JSlider(-180, 180, -45);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = ((JSlider)e.getSource()).getValue();
theta = Math.toRadians(value);
repaint();
}
});
return slider;
}

public static void main(String[] args) {
Pointing test = new Pointing();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(test);
f.add(test.getSlider(), "Last");
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
</pre>
</blockquote>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Turning images around the clock
 
Similar Threads
Move enlarged image around on mouseover - Image mapping
How to make all my graphics selectable and doubleclick with event?
Question about rescaling/rendering lots of big pictures
problem loading images
Handling MouseMovement in JTextArea