0

背景信息:我正在将prefuse 框架分配给 android(我命名为 AndroidPrefuse)。我已经完成了大部分工作,它至少适用于一个可视化(散点图)。我注意到“高”数据量(超过 10000 个项目)的 android 版本非常慢。

我注意到 prefuse(在桌面版本中)确实使用 BufferedImage 来绘制。我认为这是为了获得性能。这是代码:

protected BufferedImage m_offscreen;
...
public void paintComponent(Graphics g) {
    if (m_offscreen == null) {
        m_offscreen = getNewOffscreenBuffer(getWidth(), getHeight());
    }
    Graphics2D g2D = (Graphics2D)g;
    Graphics2D buf_g2D = (Graphics2D) m_offscreen.getGraphics();

    paintDisplay(buf_g2D, getSize());
    paintBufferToScreen(g2D);
...
protected BufferedImage getNewOffscreenBuffer(int width, int height) {
    BufferedImage img = null;
    if ( !GraphicsEnvironment.isHeadless() ) {
        try {
            img = (BufferedImage)createImage(width, height);
        } catch ( Exception e ) {
            img = null;
        }
    }
    if ( img == null ) {
        return new BufferedImage(width, height,
                                 BufferedImage.TYPE_INT_RGB);
    }
    return img;
}

起初我确实在 AndroidPrefuse 跳过了这种“缓冲”。在我注意到性能问题后,我尝试了这个:

protected void onDraw(Canvas canvas)
{
...
    int width = getWidth();
    int height = getHeight();       
    if (m_offscreen == null)
    {
         bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
         m_offscreen = new Canvas(bitmap);
    }
    paintDisplay(m_offscreen);
    canvas.drawBitmap(bitmap, 0, 0, null);
...

但结果是一样的。我是android新手,因此问题可能很简单:

第一个问题:我做对了吗,即与prefuse original 一样吗?

我感觉上面的代码和“非缓冲”是一样的:

protected void onDraw(Canvas canvas)
{
...
  paintDisplay(canvas);
...

我对吗?如果是的话,有没有办法像原来的prefuse(使用BufferedImage)一样提高我的AndroidPrefuse的速度?

“paintDisplay”方法呈现所有项目。对于 10000 个项目,它需要 1100 毫秒(在三星 Galaxy S5 上)。它看起来不多,但是当我平移和缩放时,应用程序不再流畅,因为它有 100 个项目。

作为记录:我还将 View 实现为 SurfaceView 并在单独的线程中处理方法“paintDisplay”。但这并没有提高速度。

如果使用位图来提高性能不是一个好的解决方案,有人知道如何提高性能吗?

4

0 回答 0