Show Image View from file path?

前端 未结 13 1036
眼角桃花
眼角桃花 2020-11-22 11:18

I need to show an image by using the file name only, not from the resource id.

ImageView imgView = new ImageView(this);
imgView.setBackgroundResource(R.drawa         


        
13条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 11:34

    You may use this to access a specific folder and get particular image

     public void Retrieve(String path, String Name)
       {
        File imageFile = new File(path+Name);
    
        if(imageFile.exists()){
    
            Bitmap myBitmap = BitmapFactory.decodeFile(path+Name);
            myImage = (ImageView) findViewById(R.id.savedImage);
            myImage.setImageBitmap(myBitmap);
            Toast.makeText(SaveImage.this, myBitmap.toString(), Toast.LENGTH_LONG).show();
    
        }
    }
    

    And then you can call it by

    Retrieve(Environment.getExternalStorageDirectory().toString()+"/Aqeel/Images/","Image2.PNG");
    Toast.makeText(SaveImage.this, "Saved", Toast.LENGTH_LONG).show();
    

提交回复
热议问题