动态绘制图像的最佳方法

动态绘制图像的最佳方法

本文介绍了动态绘制图像的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个具有绘制地图,我曾与laserscans探索周围的Andr​​oid应用程序。
我有我的所有数据,如电子文本文件:

I'm creating an android app that has to draw a map of an ambient that i have explored with laserscans.I have e text file with all my data like:


index x y
path   0 0 0
path   1 1 0
path   2 2 0

...etc

obstacle 0 10 10
obstacle 1 10 22

..etc

所以我的 XY 的我曾经到过的地方坐标的 XY 的障碍我见过。
我有一个线程读取从文本文件中的数据,并存储在列表数据

so I have xy coordinates of where I've been and xy of obstacles I've seen.I have a thread that reads the data from the text file and stores that data in a list.

另一个线程读取列表并提请被放在了所有点列表直到那一刻被读线程

Another thread reads that list and draws all the points that are put in the list until that moment by the reading thread.

我的问题是,我不希望每次读线程已经把新的数据到数据列表。有一种方法来绘制像一个位图和动态修改呢?我的意思是,每一个我看过一些新的数据I打开位图的时候,我添加到新的点关闭的位图,并显示在屏幕上?

My problem is that I don't want to re-read everything every time the reading thread has put new data into the data list. There is a way to draw something like a bitmap and modify this dynamically? I mean that every time I have read some new data I "open" the bitmap, I add to that the new points, "close" that bitmap and show on the screen?

我现在正在做的是阅读我的的onDraw()函数的所有名单,并开始绘制了点,但我的 170 000 点,这是一个有益的工作,因为每一个的点是在老位置的时候,我只是有一些新的点...

what I am doing now is to read all the list in my onDraw() function and draw point by point, but I have 170 000 points and that is a useful work because every time the points are in the old position, I only have some new points...

推荐答案

您可以创建一个位图,并在您的视图画布,只是不断地吸引到必要时此位图。要被吸入了一遍,绘制点要么从列表中移除点,因为他们被吸引,或保留最后一点的指数跟踪线程prevent百分点。

You can create a bitmap and a canvas in your view and just continue to draw into this bitmap as necessary. To prevent points from being drawn over again, the thread that draws the points should either remove points from the list as they are drawn, or keep track of the index of the last point.

下面是一个包含基础的例子:

Here's an example that contains the basics:

public class myView extends View {

    Bitmap mBitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
    Canvas mCanvas = new Canvas(mBitmap);
    Paint mPaint = new Paint();

    public void updateBitmap(List<Point> points) {
        while (!points.isEmpty()) {
            int x = points.get(0).x;
            int y = points.get(0).y;
            mCanvas.drawPoint(x, y, mPaint);
            points.remove(0);
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawBitmap(mBitmap, 0, 0, null);
    }
}

这绘制点的线程调用 updateBitmap ,传递点来绘制的当前列表。这些点然后从列表中,以便它们不会被再次购买上绘制除去。

The thread that draws the points calls updateBitmap, passing it the current list of points to draw. These points are then removed from the list so they will not be drawn again later on.

这篇关于动态绘制图像的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:52