2016-06-30 2 views
1

나는 SD card에있는 심상을 가지고 있고 SD card에서 심상을 가지고 가고 ImageView에서 놓았다. 나는 아래의 코드를 시도했다.ImageView에 SD 카드 이미지를 설정 하시겠습니까?

내 코드 :

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 그것이 작동합니다. –

관련 문제