BitmapFromAsset

2019. 12. 20. 15:31Kotlin

반응형
fun getBitmapFromAsset(context: Context, name: String): Bitmap?{
  val assetManager = context.assets as AssetManager
  var inputStream: InputStream
  try {
  	inputStream = assetManager.open(name)
  	return BitmapFactory.decodeStream(inputStream)
  } catch (e: IOException) {
  	e.printStackTrace()
  	return null
  }
}

// ex) name = "test.jpg" (ok) // name = "file:///android_asset/test.jpg"(not okay)
getBitmapFromAsset(this, name.replace("file:///android_asset/", ""))
반응형

'Kotlin' 카테고리의 다른 글

zip, unzip  (0) 2019.12.20
Bitmap in putExtra  (0) 2019.12.20
Snackbar  (0) 2019.12.20
MVVM  (0) 2019.12.12
delegate  (0) 2019.12.11