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