1

JFreeChart-XYLineChartに画像を描画するのに問題があります。主な問題は、注釈のx座標とy座標がリアルタイムで動的に更新されることです。そのため、私のコードでは、注釈を追加して新しい注釈を描画するためにクリアすると、ちらつきが発生し、ユーザーに迷惑をかけます。

グラフィックを使用してupdate()、paint()、またはrepaint()メソッドを使用してJAVAでのちらつきの問題の例をいくつか確認しましたが、JFreeChartでは実装できないようです。

ちらつきを取り除く方法や、注釈の代わりにJFreeChartで1つのbufferedImageを使用するための回避策について何かアイデアはありますか?

より具体的には、ここに描かれた線と画像があります:

スクリーンショット

したがって、この十字線(バッファリングされた画像として)は、x軸とy軸の更新された値でプロットラインを上下に移動する必要がありますが、この動きにより、残念ながらちらつきが発生します。

これが私が画像を描く私のコードの部分です-15以上のクラスと5kの書かれたコードがあるので私は推測するSSCCEを提供することはできません:

// After a button clicked on panel
SomeButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {

        // The chart and XYPlot is already drawn at this point 


        // Reading the image
        try {
            myPicture = ImageIO
                    .read(new File("\\\\Users2\\blabla\\Data\\MyPictures\\x.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Setting up a timer
        timer2 = new java.util.Timer();

        Object source = event.getSource();
        if (source == SomeButton) {

        // Setting up a task
            task2 = new java.util.TimerTask() {
                @Override
                public void run() {
                    double x1;
                    double y1;
                    try {
                        // Getting different x and y values from a microcontroller instantaneously
                        if (microContConnected()) {

                            x1 = microCont.getX();
                            y1 = microCont.getY();

                            // creating the annotation
                            XYImageAnnotation ImageAnn = new XYImageAnnotation(x1, y1, myPicture);

                            // Here is the drawing and clearing made !
                            plot.addAnnotation(ImageAnn);       
                            pause(50);
                            plot.clearAnnotations();    
                        }

                    } catch (SerialPortException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            };
            timer2.scheduleAtFixedRate(task2, 50, 50);
        }
    }
});
4

1 に答える 1

0

私は自分で解決策を見つけたようです; プロットに画像を追加する代わりに、レンダラーを使用します。新しい座標で画像を追加して削除する間に一時停止機能はありません。また、追加と削除の順序が逆になります。私がこのように働くことに驚いたのは、私が言わなければならないことです。ちらつきは残っていません。クリップされたグラフィックやダブルバッファリングのようにスムーズです。:)これが新しいコードです:

    // renderer
    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    // Reading the image
    try {
        myPicture = ImageIO.read(new File("\\\\Users2\\blabla\\Data\\MyPictures\\x.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Setting up a timer
    timer2 = new java.util.Timer();

    Object source = event.getSource();
    if (source == someButton) {

                task2 = new java.util.TimerTask() {
                    @Override
                    public void run() {
                        if (check == true) {
                            if (microContConnected()) {

                                 x1 = microCont.getX();
                                 y1 = microCont.getY();

                                renderer.removeAnnotations();

                                XYImageAnnotation img2 = new XYImageAnnotation(
                                        x1, y1, myPicture);
                                renderer.addAnnotation(img2,
                                        Layer.FOREGROUND);
                            }
                        }
                    }
                };
                timer2.scheduleAtFixedRate(task2, 50, 50);
            }
于 2012-12-14T17:07:03.860 に答える