2016-06-30 142 views
1

我有一個圖像在SD card我想從SD card拍攝圖像並設置在ImageView。請幫助我們我已經嘗試了下面的代碼。將SD卡圖像設置爲ImageView?

我的代碼:

sendImageFromFolder.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 

        Uri uri=null; 
        ArrayList<Uri> arrayList=new ArrayList<Uri>(); 
        ImageView imageView= (ImageView) findViewById(R.id.imageView); 

        File pictues= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
        String[] listOfPictures=pictues.list(); 
        for(String s:listOfPictures){ 
         uri=Uri.parse("file://"+ pictues.toString() +"/"+s); 
         arrayList.add(uri); 


        } 

        InputStream inputStream = null; 
        FileOutputStream fileOutputStream=null; 
        Bitmap bmp; 

        try { 
         inputStream = getContentResolver().openInputStream(arrayList.get(0)); 
        } catch (FileNotFoundException e) { 
         e.printStackTrace(); 
        } 
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); 
        bmp = BitmapFactory.decodeStream(bufferedInputStream); 

        imageView.setImageBitmap(bmp); 
       } 

回答

3
File pictureFile = new File("Path to your image"); 
Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath()); 
mImage.setImage(bitmap); 
+0

是什麼?PictureFile的 –

+0

查看已更新的答案與您的圖片路徑的文件。 –

+0

thaks bro它的工作 –