Android saves the contents of View as a simple instance of the image

  • 2020-05-24 06:10:09
  • OfStack

How it works: create a new Bitmap, then create an Canvas based on it, and finally call the draw method of View and draw View onto Canvas, so that the Bitmap we get is exactly what we want.
Code:


    public Bitmap createViewBitmap(View v) {
        Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
        Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        v.draw(canvas);
        return bitmap;
    }


Related articles: