Creating an empty bitmap and drawing though canvas in Android

后端 未结 2 2063
南方客
南方客 2020-11-28 22:49

I\'d like to create an empty bitmap and set a canvas to that bitmap and then draw any shape on the bitmap.

2条回答
  •  北海茫月
    2020-11-28 23:49

    This is probably simpler than you're thinking:

    int w = WIDTH_PX, h = HEIGHT_PX;
    
    Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
    Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
    Canvas canvas = new Canvas(bmp);
    
    // ready to draw on that bitmap through that canvas
    

    Here's a series of tutorials I've found on the topic: Drawing with Canvas Series

提交回复
热议问题