|
|
@ -29,10 +29,10 @@ object BitmapUtils { |
|
|
|
fun decodeBitmap(path: String, width: Int, height: Int): Bitmap? { |
|
|
|
fun decodeBitmap(path: String, width: Int, height: Int): Bitmap? { |
|
|
|
val op = BitmapFactory.Options() |
|
|
|
val op = BitmapFactory.Options() |
|
|
|
op.inPreferredConfig = Config.RGB_565 |
|
|
|
op.inPreferredConfig = Config.RGB_565 |
|
|
|
var ips=FileInputStream(path) |
|
|
|
val ips = FileInputStream(path) |
|
|
|
// inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; |
|
|
|
// inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; |
|
|
|
op.inJustDecodeBounds = true |
|
|
|
op.inJustDecodeBounds = true |
|
|
|
BitmapFactory.decodeStream(ips,null,op)//获取尺寸信息 |
|
|
|
BitmapFactory.decodeFileDescriptor(ips.fd, null, op) |
|
|
|
//获取比例大小 |
|
|
|
//获取比例大小 |
|
|
|
val wRatio = ceil((op.outWidth / width).toDouble()).toInt() |
|
|
|
val wRatio = ceil((op.outWidth / width).toDouble()).toInt() |
|
|
|
val hRatio = ceil((op.outHeight / height).toDouble()).toInt() |
|
|
|
val hRatio = ceil((op.outHeight / height).toDouble()).toInt() |
|
|
@ -44,9 +44,8 @@ object BitmapUtils { |
|
|
|
op.inSampleSize = hRatio |
|
|
|
op.inSampleSize = hRatio |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ips=FileInputStream(path) |
|
|
|
|
|
|
|
op.inJustDecodeBounds = false |
|
|
|
op.inJustDecodeBounds = false |
|
|
|
return BitmapFactory.decodeStream(ips,null,op) |
|
|
|
return BitmapFactory.decodeFileDescriptor(ips.fd, null, op) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 从path中获取Bitmap图片 |
|
|
|
/** 从path中获取Bitmap图片 |
|
|
@ -54,15 +53,16 @@ object BitmapUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun decodeBitmap(path: String): Bitmap? { |
|
|
|
fun decodeBitmap(path: String): Bitmap? { |
|
|
|
|
|
|
|
|
|
|
|
val opts = BitmapFactory.Options() |
|
|
|
val opts = BitmapFactory.Options() |
|
|
|
opts.inPreferredConfig = Config.RGB_565 |
|
|
|
opts.inPreferredConfig = Config.RGB_565 |
|
|
|
var ips=FileInputStream(path) |
|
|
|
val ips = FileInputStream(path) |
|
|
|
opts.inJustDecodeBounds = true |
|
|
|
opts.inJustDecodeBounds = true |
|
|
|
BitmapFactory.decodeStream(ips,null,opts) |
|
|
|
BitmapFactory.decodeFileDescriptor(ips.fd, null, opts) |
|
|
|
opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128) |
|
|
|
opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128) |
|
|
|
opts.inJustDecodeBounds = false |
|
|
|
opts.inJustDecodeBounds = false |
|
|
|
ips=FileInputStream(path) |
|
|
|
|
|
|
|
return BitmapFactory.decodeStream(ips,null,opts) |
|
|
|
return BitmapFactory.decodeFileDescriptor(ips.fd, null, opts) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|