- // Get the favorite icon bitmap drawable.
- val favoriteIconBitmapDrawable = favoriteIconDrawable as BitmapDrawable
-
- // Get the favorite icon bitmap.
- val favoriteIconBitmap = favoriteIconBitmapDrawable.bitmap
-
- // Create a favorite icon byte array output stream.
- val favoriteIconByteArrayOutputStream = ByteArrayOutputStream()
-
- // Convert the bitmap to a PNG and place it in the byte array output stream. `0` is for lossless compression (the only option for a PNG).
- favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream)
-
- // Convert the favorite icon byte array output stream to a byte array.
- val favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray()
-