Skip to content

Commit

Permalink
Merge pull request #56 from tconns/fix/thumbhash-android
Browse files Browse the repository at this point in the history
fix: 🐛 thumbhash android
  • Loading branch information
gtokman authored Sep 13, 2024
2 parents 3773c7a + b3eb118 commit 14e0422
Showing 1 changed file with 10 additions and 10 deletions.
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

0 comments on commit 14e0422

Please sign in to comment.