Tag: image rotation

Java旋转图像变成背景黑色的一部分

当我尝试旋转图像时,看起来背景的一部分变黑(我的图像是透明的) 背景白色 背景的一部分变黑 这是旋转图像的代码: public BufferedImage rotate(int height, int width, BufferedImage originalImg, int angle) { BufferedImage rotateImage = null; try { rotateImage = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB); AffineTransform a90 = AffineTransform.getRotateInstance(Math.toRadians(angle), height / 2, width / 2); AffineTransformOp op90 = new AffineTransformOp(a90, AffineTransformOp.TYPE_BILINEAR); op90.filter(originalImg, rotateImage); } catch (Exception e) { System.err.println(e); } return rotateImage; }

获得正确的图像观察者来旋转图像

所以我画了一个BufferedImage’鸟’,但我想根据它落下的角度旋转它。 我有一个鸟对象,它包含BufferedImage和一个render()方法,它旋转绘制它。 public void render(Graphics2D g, ImageObserver io) { double theta = Math.tan((height – pastHeight) / .875); System.out.println(theta); Graphics2D g2 = (Graphics2D) bird.getGraphics(); g2.drawImage(bird, 100, (int) height, null); g2.rotate(theta); g2.drawImage(bird, 100, (int) height, io); } 我这样称呼它 bird.render(g2, ???); 在我的jcomponent中的paintcomponent方法中。 唯一的问题是我不知道该使用什么作为我的ImageObserver …我已经尝试传递我的JFrame和我的JComponent但是当我这样做时图像不再出现…我会传递什么图像出现在我的窗口和/或我怎么能实现这种旋转?