2016-10-06 16 views
-1

私は現在アンドロイドを学んでおり、連絡先のようなアプリケーションを作っています。Android - ギャラリーから画像を選択して後で使用できるように保存するにはどうすればいいですか?

ユーザーは連絡先を作成できます。連絡先は現在sql liteデータベースに追加されます。

連絡先の作成/編集時にギャラリーから画像を選択できるオプションを追加できます。

携帯電話のギャラリーから画像を選択し、その画像の場所を個々の連絡先に保存して後で表示できるようにするにはどうすればよいですか?

答えて

0

使用バイト配列への画像変換の画像を保存して、DBに保存するためには画像

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (requestCode == 9000 && resultCode == RESULT_OK && null != data) { 
     Uri selectedImage = data.getData(); 
     String[] filePathColumn = {MediaStore.Images.Media.DATA}; 

     Cursor cursor = getContentResolver().query(selectedImage, 
       filePathColumn, null, null, null); 
     cursor.moveToFirst(); 

     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String picturePath = cursor.getString(columnIndex); 
     cursor.close(); 

     ImageView imageView = (ImageView) findViewById(R.id.galpic); 
     imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

    } 

} 

を取得するための画像ピッカー

Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    startActivityForResult(Intent.createChooser(intent,"Select Picture"), 9000); 

使用これを起動するには、この目的。ビットマップはイメージを含むビットマップオブジェクトです

ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); 
      byte[] b = baos.toByteArray(); 
String string_file = Base64.encodeToString(b, Base64.DEFAULT); 
関連する問題