@@ -21,6 +21,7 @@ import android.content.Context
21
21
import android.content.Intent
22
22
import android.content.Intent.createChooser
23
23
import android.graphics.Bitmap
24
+ import android.graphics.Canvas
24
25
import android.graphics.Picture
25
26
import android.media.MediaScannerConnection
26
27
import android.net.Uri
@@ -165,6 +166,7 @@ fun BitmapFromComposableSnippet() {
165
166
drawIntoCanvas { canvas -> canvas.nativeCanvas.drawPicture(picture) }
166
167
}
167
168
}
169
+
168
170
) {
169
171
ScreenContentToCapture ()
170
172
}
@@ -205,15 +207,19 @@ private fun ScreenContentToCapture() {
205
207
206
208
private fun createBitmapFromPicture (picture : Picture ): Bitmap {
207
209
// [START android_compose_draw_into_bitmap_convert_picture]
208
- val bitmap = Bitmap .createBitmap(
209
- picture.width,
210
- picture.height,
211
- Bitmap .Config .ARGB_8888
212
- )
213
-
214
- val canvas = android.graphics.Canvas (bitmap)
215
- canvas.drawColor(android.graphics.Color .WHITE )
216
- canvas.drawPicture(picture)
210
+ val bitmap = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
211
+ Bitmap .createBitmap(picture)
212
+ } else {
213
+ val bitmap = Bitmap .createBitmap(
214
+ picture.width,
215
+ picture.height,
216
+ Bitmap .Config .ARGB_8888
217
+ )
218
+ val canvas = android.graphics.Canvas (bitmap)
219
+ canvas.drawColor(android.graphics.Color .WHITE )
220
+ canvas.drawPicture(picture)
221
+ bitmap
222
+ }
217
223
// [END android_compose_draw_into_bitmap_convert_picture]
218
224
return bitmap
219
225
}
0 commit comments