core-ktx / androidx.view / android.view.View / toBitmap

toBitmap

fun View.toBitmap(config: Config = Bitmap.Config.ARGB_8888): Bitmap

Return a Bitmap representation of this View.

The resulting bitmap will be the same width and height as this view's current layout dimensions. This does not take into account any transformations such as scale or translation.

Note, this will use the software rendering pipeline to draw the view to the bitmap. This may result with different drawing to what is rendered on a hardware accelerated canvas (such as the device screen).

If this view has not been laid out this method will throw a IllegalStateException.

Parameters

config - Bitmap config of the desired bitmap. Defaults to Bitmap.Config.ARGB_8888.