How to blit() in android?

后端 未结 2 566
旧巷少年郎
旧巷少年郎 2020-12-13 16:15

I\'m used to handle graphics with old-school libraries (allegro, GD, pygame), where if I want to copy a part of a bitmap into another... I just use blit.

I\'m trying

2条回答
  •  既然无缘
    2020-12-13 16:25

    In android you draw to the canvas, and when you want it to update you call invalidate which will the redraw this canvas to the screen. So I'm guessing you have overridden the onDraw method of your view so just add invalidate();

    @Override
    public void onDraw(Canvas canvas) {
        // Draw a bitmap to the canvas at 0,0
        canvas.drawBitmap(mBitmap, 0, 0, null);
        // Add in your drawing functions here
        super.onDraw(canvas);
        // Call invalidate to draw to screen
        invalidate();
    }
    

    The above code simply redraws the bitmap constantly, of course you want to add in extra thing to draw and consider using a timing function that calls invalidate so that it is not constantly running. I'd advice having a look at the lunarlander sources.

提交回复
热议问题