1

로컬 저장소의 폴더에 20k 개의 이미지 파일이 있습니다. 로컬 저장소의 파일 이름으로 이미지를 표시해야합니다. 그것을하는 방법? 나는 여기에 내 코드를 첨부 :android의 로컬 저장소에서 이미지를 표시 할 수 없습니다.

if (Environment.getExternalStorageState() 
      .equals(Environment.DIRECTORY_PICTURES)) { 
     String filePath = File.separator + "sdcard" + File.separator + "Android" + File.separator + "obb" + File.separator + "convertMp3ToDb" + File.separator + "ldoce6pics" + File.separator + fileName; 
     try { 
      FileInputStream fis = new FileInputStream(filePath); 
      String entry = null; 
      while ((entry = fis.toString()) != null) { 
       if (!entry.toString().isEmpty()) { 
        File Mytemp = File.createTempFile("TCL", "jpg", getContext().getCacheDir()); 
        Mytemp.deleteOnExit(); 
        FileOutputStream fos = new FileOutputStream(Mytemp); 
        for (int c = fis.read(); c != -1; c = fis.read()) { 
         try { 
          fos.write(c); 
         } catch (IOException e) { 
          e.printStackTrace(); 
         } 
        } 
        fos.close(); 
        FileInputStream MyFile = new FileInputStream(Mytemp); 
        final Bitmap bit = BitmapFactory.decodeStream(MyFile); 
        imageView.setImageBitmap(bit); 

       } 
      } 
      fis.close(); 

     } catch (IOException e) { 
      e.printStackTrace(); 

     } 
    } 
+0

모든 로그 캣 오류처럼해야 할

if (Environment.getExternalStorageState() .equals(Environment.DIRECTORY_PICTURES)) { // this never be true see below image } 

enter image description here

를? – Nisarg

+0

show ur logcat log – MobDev

+0

시도해보십시오. 글라이드와 같은 이미지 라이브러리를 사용하십시오 (글라이드를 선호하는 다른 사람들도 있습니다) - 문자열에서 uri로 파일 경로를 변환하는 경우 2. 비트 맵으로 로더를 설정할 수도 있습니다 – MobDev

답변

3
if (Environment.getExternalStorageState() 
      .equals(Environment.DIRECTORY_PICTURES)) { 
     String filePath = File.separator + "sdcard" + File.separator + "Android" + File.separator + "obb" + File.separator + "convertMp3ToDb" + File.separator + "ldoce6pics" + File.separator + fileName; 
     File f = new File(filePath); 
     if(f.exits()){ 

      Bitmap bm = BitmapFactory.decodeFile(f.getAbsolutePath()); 
      imageView.setImageBitmap(bm); 

     }else{ 
      // invalid path 
      } 
    } 
    } 

업데이트 섹션 :이

File file = new File(Environment.getExternalStorageState()+"/Android/obb/convertMp3ToDb/ldoce6pics/"+fileName); 

     if (file.exists()) { 
      // your condition should ne likr this. 
     } 
+0

if (Environment.getExternalStorageState() .equals (Environment.DIRECTORY_PICTURES))이 조건이 거짓인지 알 수 있습니까? 내 생각에 –

+0

내 의견으로는 잘못된 방식으로 수행하고 있습니까? \t if (Environment.getExternalStorageState() .equals (Environment.DIRECTORY_PICTURES)) 절대로 true가 아님 –

+0

그런 다음 내부 저장소 이미지에 액세스하는 방법 –

관련 문제