//使用Bitmap加Matrix来缩放
fun resizeImage(bitmap: Bitmap, width: Int, height: Int): Bitmap {
val bmpWidth = bitmap.width
val bmpHeight = bitmap.height
val scaleWidth = width.toFloat() / bmpWidth
val scaleHeight = height.toFloat() / bmpHeight
val matrix = Matrix()
matrix.postScale(scaleWidth, scaleHeight)
return Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true)
}
//使用Bitmap加Matrix来翻转
fun horverImage(bitmap: Bitmap, H: Boolean, V: Boolean): Bitmap {
val bmpWidth = bitmap.width
val bmpHeight = bitmap.height
val matrix = Matrix()
if (H) matrix.postScale(-1f, 1f) //水平翻转H
if (V) matrix.postScale(1f, -1f) //垂直翻转V
if (H && V) matrix.postScale(-1f, -1f) //水平&垂直翻转HV
return Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true)
//matrix.postRotate(-90); //旋转-90度
}