Skip to content Skip to sidebar Skip to footer

Best Way To Draw An Image Dynamically

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

Solution 1:

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:

publicclassmyViewextendsView {

    BitmapmBitmap= Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
    CanvasmCanvas=newCanvas(mBitmap);
    PaintmPaint=newPaint();

    publicvoidupdateBitmap(List<Point> points) {
        while (!points.isEmpty()) {
            intx= points.get(0).x;
            inty= points.get(0).y;
            mCanvas.drawPoint(x, y, mPaint);
            points.remove(0);
        }
    }

    @OverrideprotectedvoidonDraw(Canvas canvas) {
        canvas.drawBitmap(mBitmap, 0, 0, null);
    }
}

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.

Post a Comment for "Best Way To Draw An Image Dynamically"