2011-08-05 23 views
1

インターネットから複数の画像をsdcardに保存し、パスをデータベースに保存する方法は?複数の画像の場合、どうすればよいですか?データベースに画像を保存する方法

"create table table1 (_id integer primary key autoincrement, " 
        + "title text not null, definition text not null, image BLOB not null);"; 

が、1つの値を格納するために私は、同じ画像があるすべてのタイトルのためにそう

 bmOptions = new BitmapFactory.Options(); 
     bmOptions.inSampleSize = 1; 
     bm = Loadmage(image_URL, bmOptions); 

     mImageV.setImageBitmap(bm); 


     extStorageDirectory = Environment.getExternalStorageDirectory().toString(); 

     OutputStream outStream = null; 
      File file = new File(extStorageDirectory, "er.PNG"); 
      try{ 
      outStream = new FileOutputStream(file); 
      bm.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
      outStream.flush(); 
      outStream.close(); 
      }catch (FileNotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

として挿入されている。今まで私は..です

表は、クエリを作成したのは以下です表示...異なるタイトルの異なる画像を表示したい。

+2

問題がありますか? iレコードをデータベースに1つ保存するか?おそらく、あなたのdbテーブルがどのように見えるかというような、より詳細な質問が必要です。 – aha

答えて

1

サーバーの名前として画像の名前を使用する必要があります。 あなたはちょうどディレクトリ

とイメージ名CONCAT例えば持た

はあなたがイメージ名rose.jpg を持っていて、SDカードに保存したい場合は、その後

File file = new File(Environment.getExternalStorageDirectory(), "/backup/" + rose.jpg); 

と仮定し、ファイル名のパスを保存することができます

String path = file.getAbsolutePath(); 
関連する問題