/**
* Created by kingadmin on 2018/4/17.
*/
class BitmapUtil private constructor(private val context: Context) {
/**
* 文件转Bitmap
*/
fun fileToBitmap(filePath: String): Bitmap {
val file = File(filePath)
val options = BitmapFactory.Options()
/**
* 压缩长宽各为一半避免图片过大装载不了
*/
options.inPurgeable = true
options.inSampleSize = 2
return BitmapFactory.decodeFile(filePath, options)
}
/**
* Bitmap转文件
*/
fun bitmapToFile(bitmap: Bitmap, saveFilePath: String): File? {
val file = File(saveFilePath)//将要保存图片的路径
try {
val bos = BufferedOutputStream(FileOutputStream(file))
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos)
bos.flush()
bos.close()
return file
} catch (e: IOException) {
e.printStackTrace()
return null
}
}
/**
* 数组