2011-11-08 4 views
0

장치 카메라의 이미지를 SD 카드의 디렉토리 (예 : /sdcard/appName/image.jpg)에 저장하고 데이터베이스에 저장합니다. 내 문제는 커서 어댑터를 사용하여 이미지를 ListView에로드 할 수없는 것입니다.파일 경로에서 이미지를 어떻게 설정할 수 있습니까?

다음 코드를 시도했습니다. helper.getImg();String (파일 경로)을 반환하는 데이터베이스 도우미의 메서드이지만 작동하지 않습니다.

icon=(ImageView)row.findViewById(R.id.icon_pura); 
String imgPath=helper.getImg(c); 
Bitmap myBitmap=BitmapFactory.decodeFile(imgPath); 
icon.setImageBitmap(myBitmap); 

답변

0

대답은 URI를 함께 할 수있다, 당신은 externalstorage() 기능을 사용해야합니다. 경로 설정을 사용하면

어쨌든 당신이 그 경로

0
String filepath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Directory name/"; 
File file = new File(filepath,imagename); 
FileInputStream fs = null; 
try 
{ 
    fs = new FileInputStream(file); 
} 
catch (FileNotFoundException e) { 
// TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

BitmapFactory.Options bfOptions = new BitmapFactory.Options(); 
      /* 
      * bfOptions.inDither=false; //Disable Dithering mode 
      * bfOptions.inPurgeable=true; //Tell to gc that whether it needs 
      * free memory, the Bitmap can be cleared 
      * bfOptions.inInputShareable=true;*/ 

bfOptions.inJustDecodeBounds = false; 
bfOptions.inTempStorage = new byte[32 * 1024]; 
try { 
    Bitmap originalImage = BitmapFactory.decodeFileDescriptor(fs.getFD(), null,bfOptions); 
    icon.setImageBitmap(originalImage); 
} catch (IOException e) { 
// TODO Auto-generated catch block 
       e.printStackTrace(); 
} 
0

당신이 himanshu의의 (올바른)의 조언을 따르는 경우에 항목을 검색하고 parsings 더 유연하다 URI로 경로를 저장하는 모든 장치에서 작동하지 않습니다 만들 사용자가 이미지를로드하고 다시로드 할 수있게하려면 수동으로 확인해야합니다. icon.setImageBitmap (null); 왜냐하면 안드로이드가 그 메모리를 유출하고 앱을 망칠 것이기 때문입니다. 100 % 일관성이 아니며로드하는 이미지의 크기와 관련이 있습니다. 그러나 며칠 전에이 누설을 발견했으며 100 % 확신합니다.

관련 문제