大家好,我想实现一个旋转的方法,比如
imageRotate(Image img1,double angle){
............................
}
传入一个Image对象,,,和要旋转的angle角度,,,然后就能返回一个旋转之后的Image对象,,,,谢谢了!!!!
imageRotate(Image img1,double angle){
............................
}
传入一个Image对象,,,和要旋转的angle角度,,,然后就能返回一个旋转之后的Image对象,,,,谢谢了!!!!
解决方案 »
- 如何使用线程
- 十万火急,请帮忙解决乱码问题
- 怎样将bufferedImage转成byte[](散分)
- 菜鸟有个紧急问题麻烦各位大虾
- Class.forName("oracle.jdbc.driver.OracleDriver")走不下去,class12.zip已经放到jbuilder7\lib下了改为class12.jar了
- ThreadLocal的疑问?
- 小弟有一个问题,关于.......
- !!!!!!!!!!!!!!!!!!!!!!!!再来将浮点数组转化为String型数组(在线等)
- 简单问题
- 关于apache的问题
- Deque到底有没有索引的概念!
- struts+hibernate中文乱码问题,分不够就加!
private Image rotate90(Image original, boolean clockwise, ImageObserver observer) { //加个参数double angle
int width = original.getWidth(observer);
int height = original.getHeight(observer);
BufferedImage bufferedImage = new BufferedImage(height,
width, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bufferedImage.createGraphics();
if(clockwise) {
AffineTransform aff = AffineTransform.getRotateInstance(Math.toRadians(90), 0, 0); //90替换成参数double angle
g2.setTransform(aff);
g2.drawImage(original, 0, -height , observer);
}
else {
AffineTransform aff = AffineTransform.getRotateInstance(Math.toRadians(-90), 0, 0);
g2.setTransform(aff);
g2.drawImage(original, -width, 0, observer);
}
return bufferedImage;
}
public Image imageRotate(Image image, double angle)
{
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
ImageIcon tempImage = new ImageIcon(image);
double radians = Math.toRadians(angle % 360);
int oldWidth = tempImage.getIconWidth();
int oldHeight = tempImage.getIconHeight();
int newWidth = (int)(Math.abs(Math.cos(radians) * oldWidth) + Math.abs(Math.sin(radians) * oldHeight));
int newHeight = (int)(Math.abs(Math.sin(radians) * oldWidth) + Math.abs(Math.cos(radians) * oldHeight));
int centerX = newWidth / 2;
int centerY = newHeight / 2;
BufferedImage ret = config.createCompatibleImage(newWidth, newHeight, Transparency.BITMASK);
Graphics2D g2d = (Graphics2D)ret.getGraphics();
g2d.rotate(radians, centerX, centerY);
g2d.drawImage(image, (newWidth - oldWidth) / 2, (newHeight - oldHeight) / 2, null); return ret;
}