E
e4_java
public class object
{
int x,y
double angle
BufferedImage bi;
JFrame owner;
public void rotate(double angleIncrease)
{
angle += angleIncrease;
Graphics2D g2 = bi.createGraphics();
g2.rotate( Math.toRadians( angleIncrease ) ); // this should rotate
the image stored in bi
// ensure angle is between 0 and 360
if(angle > 360) angle-=360;
if(angle < 0) angle+=360;
}
public void paint(Graphics g)
{
g.drawImage( bi, x, y, owner );
}
}
the image shows up, but rotate doesn't work
calling the rotate method changes the angle value, but the next time
paint is called the image show up unrotated
also rotating the context the method paint draws to won't help because
there will be more than one image displayed on it; each at its own
angle
the buffered image is first produced like this if this makes a
diffence:
// load image from file using swing.ImageIcon
ImageIcon i = new ImageIcon("filename");
// create a blank buffered image with the deminsions of the imageicon
BufferedImage img = new BufferedImage( i.getWidth(), i.getHieght(),
BufferedImage.BufferedImage.TYPE_3BYTE_BGR );
// get the graphics context of the bufferedimage and paint the icon
on to it
Graphics2D g = img.createGraphics();
i.paintIcon( null, g, 0, 0 );
{
int x,y
double angle
BufferedImage bi;
JFrame owner;
public void rotate(double angleIncrease)
{
angle += angleIncrease;
Graphics2D g2 = bi.createGraphics();
g2.rotate( Math.toRadians( angleIncrease ) ); // this should rotate
the image stored in bi
// ensure angle is between 0 and 360
if(angle > 360) angle-=360;
if(angle < 0) angle+=360;
}
public void paint(Graphics g)
{
g.drawImage( bi, x, y, owner );
}
}
the image shows up, but rotate doesn't work
calling the rotate method changes the angle value, but the next time
paint is called the image show up unrotated
also rotating the context the method paint draws to won't help because
there will be more than one image displayed on it; each at its own
angle
the buffered image is first produced like this if this makes a
diffence:
// load image from file using swing.ImageIcon
ImageIcon i = new ImageIcon("filename");
// create a blank buffered image with the deminsions of the imageicon
BufferedImage img = new BufferedImage( i.getWidth(), i.getHieght(),
BufferedImage.BufferedImage.TYPE_3BYTE_BGR );
// get the graphics context of the bufferedimage and paint the icon
on to it
Graphics2D g = img.createGraphics();
i.paintIcon( null, g, 0, 0 );