Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 thumbhash android #56

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,17 @@ import com.facebook.react.uimanager.events.RCTEventEmitter

private fun makeThumbHash(view: AppCompatImageView, hash: String): Drawable {
val thumbHash = ThumbHash.thumbHashToRGBA(Base64.decode(hash, Base64.DEFAULT))
val bitmap = Bitmap.createBitmap(thumbHash.width, thumbHash.height, Bitmap.Config.ARGB_8888)
bitmap.setPixels(toIntArray(thumbHash.rgba), 0, thumbHash.width, 0, 0, thumbHash.width, thumbHash.height)
return BitmapDrawable(view.context.resources, bitmap)
}

private fun toIntArray(byteArray: ByteArray): IntArray {
val intArray = IntArray(byteArray.size)
for (i in byteArray.indices) {
intArray[i] = byteArray[i].toInt() and 0xFF
val intArray = IntArray(thumbHash.width * thumbHash.height)
for (i in intArray.indices) {
val r = thumbHash.rgba[i * 4].toInt() and 0xFF
val g = thumbHash.rgba[i * 4 + 1].toInt() and 0xFF
val b = thumbHash.rgba[i * 4 + 2].toInt() and 0xFF
val a = thumbHash.rgba[i * 4 + 3].toInt() and 0xFF
intArray[i] =
((a and 0xff) shl 24) or ((r and 0xff) shl 16) or ((g and 0xff) shl 8) or (b and 0xff)
}
return intArray
val bitmap = Bitmap.createBitmap(intArray, thumbHash.width, thumbHash.height, Bitmap.Config.ARGB_8888)
return BitmapDrawable(view.context.resources, bitmap)
}

companion object {
Expand Down
Loading