Convert a File Object to Bitmap Convert a File Object to Bitmap android android

Convert a File Object to Bitmap


You should be able to use BitmapFactory:

File mSaveBit; // Your image fileString filePath = mSaveBit.getPath();  Bitmap bitmap = BitmapFactory.decodeFile(filePath);mImageView.setImageBitmap(bitmap);


  1. Define File

    String fileName = "/myImage.jpg";File file = new File(fileName); 
  2. get Bitmap of Image

    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
  3. Set Bitmap to ImageView

    myImageView.setImageBitmap(bitmap);


You can use this function to get Bitmap from file path

fun getBitmap(filePath:String):Bitmap?{    var bitmap:Bitmap?=null    try{        var f:File = File(path)        var options = BitmapFactory.Options()        options.inPreferredConfig = Bitmap.Config.ARGB_8888        bitmap = BitmapFactory.decodeStream(FileInputStream(f),null,options)    }catch (e:Exception){    }    return bitmap}