-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed893c3
commit 4d5d9ef
Showing
4 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/main/java/me/ash/reader/ui/component/base/Base64Image.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package me.ash.reader.ui.component.base | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import android.util.Base64 | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
|
||
@Composable | ||
fun Base64Image( | ||
modifier: Modifier = Modifier, | ||
base64Uri: String | ||
) { | ||
val bitmap = base64ToBitmap(base64Uri) | ||
val imageBitmap = bitmap.asImageBitmap() | ||
|
||
Image( | ||
bitmap = imageBitmap, | ||
modifier = modifier, | ||
contentDescription = null | ||
) | ||
} | ||
|
||
fun base64ToBitmap(base64String: String): Bitmap { | ||
val base64Data = base64String.substringAfter("base64,") | ||
val imageBytes = Base64.decode(base64Data, Base64.DEFAULT) | ||
return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size) | ||
} |