我需要能够单独旋转图像(在java中).到目前为止我唯一发现的是g2d.drawImage(image,affinetransform,ImageObserver).不幸的是,我需要在特定的点绘制图像,并且没有一个方法可以分别对图像进行旋转,并且2.允许我设置x和y.任何帮助表示赞赏
我正在寻找旋转图像.我有一个JInternalFrame包含一个JLabel.标签包含图像.旋转图像后,我需要调整内部框架的大小.我目前的代码旋转图像,但图像边缘周围有黑色,并且偏离中心.对于如何解决这个问题,有任何的建议吗?
public void rotateIcon(int angle)
{
int w = theLabel.getIcon().getIconWidth();
int h = theLabel.getIcon().getIconHeight();
int type = BufferedImage.TYPE_INT_RGB; // other options, see api
BufferedImage DaImage = new BufferedImage(h, w, type);
Graphics2D g2 = DaImage.createGraphics();
double x = (h - w)/2.0;
double y = (w - h)/2.0;
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.toRadians(angle), w/2.0, h/2.0);
g2.drawImage(new ImageIcon(getData()).getImage(), at, theLabel);
g2.dispose();
theLabel.setIcon(new ImageIcon(DaImage));
this.setSize(DaImage.getWidth(),DaImage.getHeight()); //resize the frame
}
Run Code Online (Sandbox Code Playgroud)