pull/1785/head
kunfei 3 years ago
parent d57250df32
commit 4647c8ecd2
  1. 11
      app/src/main/java/io/legado/app/utils/BitmapUtils.kt

@ -7,7 +7,6 @@ import android.graphics.*
import android.graphics.Bitmap.Config
import android.view.View
import com.google.android.renderscript.Toolkit
import java.io.FileInputStream
import java.io.IOException
import kotlin.math.*
@ -27,10 +26,9 @@ object BitmapUtils {
@Throws(IOException::class)
fun decodeBitmap(path: String, width: Int, height: Int): Bitmap {
val op = BitmapFactory.Options()
val ips = FileInputStream(path)
// inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight;
op.inJustDecodeBounds = true
BitmapFactory.decodeFileDescriptor(ips.fd, null, op)
BitmapFactory.decodeFile(path, op)
//获取比例大小
val wRatio = ceil((op.outWidth / width).toDouble()).toInt()
val hRatio = ceil((op.outHeight / height).toDouble()).toInt()
@ -43,7 +41,7 @@ object BitmapUtils {
}
}
op.inJustDecodeBounds = false
return BitmapFactory.decodeFileDescriptor(ips.fd, null, op)
return BitmapFactory.decodeFile(path, op)
}
/** 从path中获取Bitmap图片
@ -53,12 +51,11 @@ object BitmapUtils {
@Throws(IOException::class)
fun decodeBitmap(path: String): Bitmap {
val opts = BitmapFactory.Options()
val ips = FileInputStream(path)
opts.inJustDecodeBounds = true
BitmapFactory.decodeFileDescriptor(ips.fd, null, opts)
BitmapFactory.decodeFile(path, opts)
opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128)
opts.inJustDecodeBounds = false
return BitmapFactory.decodeFileDescriptor(ips.fd, null, opts)
return BitmapFactory.decodeFile(path, opts)
}
/**

Loading…
Cancel
Save