java中bufferedImage对象的当前坐标

时间:2014-03-16 12:27:12

标签: java

无论如何在jpanel上找到缓冲图像的当前位置?

我在缓冲区上绘制一个图像,命名为currentImage。现在我想通过使用仿射变换在Panel中移动它。

要使用鼠标进行翻译,我必须知道当前位置,新位置并更新新位置。

但是我在获取BufferedImage的当前位置时遇到了麻烦。 IDE的建议中没有任何方法可以工作。

任何人都可以告诉我如何做到这一点?谢谢!

修改

这是我的draw和paintComponent方法:

private void draw(){
        AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC);
        int w = this.getWidth();    int h = this.getHeight();

        if (currentImage == null || width != w || height != h){
            width = w;
            height = h;

            currentImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

            graphics = currentImage.createGraphics();
            graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
            drawClearAndGradedArea(graphics);
            drawActualRunway(graphics, width, height, width, height);
            drawLeftToRight(graphics);
            drawRightToLeft(graphics);
            drawCentralLine(graphics);
            graphics.setComposite(ac);
        }
    }

的paintComponent()

@Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2d = (Graphics2D) g.create();
        g2d.clearRect(0,0, this.getWidth(), this.getHeight());
        RenderingHints rh = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHints(rh);
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        /*
         * main components on panel
         */

        this.draw();
        this.animation();

        g2d.drawImage(currentImage, transform, this);

        drawNote(g2d);
        g2d.dispose();
    }

0 个答案:

没有答案