Skip to content

Commit

Permalink
修复原图浏览时解析部分大图显示不全的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojieonly committed Feb 9, 2025
1 parent 70ad7bd commit 25e56bb
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/src/main/java/com/hippo/lib/image/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.io.FileInputStream
import java.nio.channels.FileChannel
import kotlin.math.max
import kotlin.math.min
import androidx.core.graphics.createBitmap

class Image private constructor(
source: FileInputStream?,
Expand Down Expand Up @@ -56,8 +57,8 @@ class Image private constructor(
// Sadly we must use software memory since we need copy it to tile buffer, fuck glgallery
// Idk it will cause how much performance regression
val screenSize = min(
info.size.width / (2 * screenWidth),
info.size.height / (2 * screenHeight)
info.size.width / screenWidth,
info.size.height / screenHeight
).coerceAtLeast(1)
decoder.setTargetSampleSize(
max(screenSize, simpleSize ?: 1)
Expand Down Expand Up @@ -98,7 +99,7 @@ class Image private constructor(
?: mObtainedDrawable!!.intrinsicHeight
val isRecycled = mObtainedDrawable == null

var started = false
private var started = false

@Synchronized
fun recycle() {
Expand All @@ -120,7 +121,7 @@ class Image private constructor(

private fun prepareBitmap() {
if (mBitmap != null) return
mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
mBitmap = createBitmap(width, height)
}

private fun updateBitmap() {
Expand Down Expand Up @@ -184,10 +185,13 @@ class Image private constructor(
if (mObtainedDrawable == null) {
return
}
if (mObtainedDrawable is BitmapDrawable){
if (mObtainedDrawable is BitmapDrawable) {
(mObtainedDrawable as BitmapDrawable).bitmap
}else{
val stickerBitmap = Bitmap.createBitmap(mObtainedDrawable!!.intrinsicWidth, mObtainedDrawable!!.intrinsicHeight, Bitmap.Config.ARGB_8888)
} else {
val stickerBitmap = createBitmap(
mObtainedDrawable!!.intrinsicWidth,
mObtainedDrawable!!.intrinsicHeight
)
val canvas = Canvas(stickerBitmap)
mObtainedDrawable!!.setBounds(0, 0, stickerBitmap.width, stickerBitmap.height)
mObtainedDrawable!!.draw(canvas)
Expand All @@ -202,7 +206,7 @@ class Image private constructor(
width,
height
)
}catch (e:ClassCastException){
} catch (e: ClassCastException) {
FirebaseCrashlytics.getInstance().recordException(e)
return
}
Expand Down

0 comments on commit 25e56bb

Please sign in to comment.