Create a Bitmap/Drawable from file path

后端 未结 6 1083
故里飘歌
故里飘歌 2020-11-28 06:56

I\'m trying to create a Bitmap or Drawable from existing file path.

String path = intent.getStringExtra(\"FilePath\");
BitmapFactory.Options option = new Bit         


        
6条回答
  •  时光取名叫无心
    2020-11-28 07:38

    It works for me:

    File imgFile = new  File("/sdcard/Images/test_image.jpg");
    if(imgFile.exists()){
        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        //Drawable d = new BitmapDrawable(getResources(), myBitmap);
        ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
        myImage.setImageBitmap(myBitmap);
    
    }
    

    Edit:

    If above hard-coded sdcard directory is not working in your case, you can fetch the sdcard path:

    String sdcardPath = Environment.getExternalStorageDirectory().toString();
    File imgFile = new  File(sdcardPath);
    

提交回复
热议问题