2011-11-08 7 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

あなたはヒマンシュさん(正しい)アドバイスに従う場合でアイテムを取得し、parsingsため、より柔軟性のあるURIへのパスを格納し、すべてのデバイス上で動作しません、作りますユーザーにイメージの読み込みと再読み込みのオプションを許可する場合は、必ず手動でicon.setImageBitmap(null);を確認してください。あなたのアプリをクラッシュさせてしまうからです。それは100%一貫しているわけではなく、読み込んでいる画像のサイズに関係していますが、私は数日前にこの漏れを見つけ、それがそこにあることを100%確信しています。

関連する問題