|
|
|
@ -10,6 +10,7 @@ import android.graphics.Color |
|
|
|
|
import com.google.android.renderscript.Toolkit |
|
|
|
|
import java.io.FileInputStream |
|
|
|
|
import java.io.IOException |
|
|
|
|
import java.io.InputStream |
|
|
|
|
import kotlin.math.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -81,6 +82,23 @@ object BitmapUtils { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 从path中获取Bitmap图片 |
|
|
|
|
* @param path 图片路径 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
fun decodeBitmap(inputStream: InputStream): Bitmap? { |
|
|
|
|
return inputStream.use { |
|
|
|
|
val opts = BitmapFactory.Options() |
|
|
|
|
opts.inJustDecodeBounds = true |
|
|
|
|
|
|
|
|
|
BitmapFactory.decodeStream(inputStream, null, opts) |
|
|
|
|
opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128) |
|
|
|
|
opts.inJustDecodeBounds = false |
|
|
|
|
BitmapFactory.decodeStream(inputStream, null, opts) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 以最省内存的方式读取本地资源的图片 |
|
|
|
|
* @param context 设备上下文 |
|
|
|
|