**try this out**
val bitmap = assetsToBitmap("ic_launcher_background")
private fun assetsToBitmap(fileName:String): Bitmap?{
return try{
val stream = assets.open(fileName)
BitmapFactory.decodeStream(stream)
}catch (e: IOException){
e.printStackTrace()
null
}
}
// Method to convert a bitmap to bitmap drawable
private fun bitmapToDrawable(bitmap:Bitmap): BitmapDrawable {
return BitmapDrawable(resources,bitmap)
}
This worked for me!
public Bitmap readAssetsBitmap(String filename) throws IOException {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeStream(assets.open(filename), null, options);
if(bitmap == null) {
throw new IOException("File cannot be opened: It's value is null");
} else {
return bitmap;
}
} catch (IOException e) {
throw new IOException("File cannot be opened: " + e.getMessage());
}
}