1

i have this code .. which work perfectly when i click the button i will choose a picture from my device gallery and then view it on imageview what i want to do is can i save the slected image into drawable file o my database ?

package com.example.testpic; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends Activity { Button btnGal; ImageView ivGalImg; Bitmap bmp; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnGal = (Button)findViewById(R.id.btnGallary); ivGalImg = (ImageView)findViewById(R.id.ivImage); btnGal.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { openGallery(); } }); } private void openGallery() { Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); } @Override protected void onActivityResult(int requestCode, int resultcode, Intent intent) { super.onActivityResult(requestCode, resultcode, intent); if (requestCode == 1) { if (intent != null && resultcode == RESULT_OK) { Uri selectedImage = intent.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 filePath = cursor.getString(columnIndex); cursor.close(); if(bmp != null && !bmp.isRecycled()) { bmp = null; } bmp = BitmapFactory.decodeFile(filePath); ivGalImg.setBackg`enter code here`roundResource(0); ivGalImg.setImageBitmap(bmp); } else { Log.d("Status:", "Photopicker canceled"); } } } } 

1 Answer 1

1
  1. you can not save images to your drawable folder after your apk file has been generated
  2. you can save the path of image to your db
  3. You can copy the image and past it to storage of your mobile programmatically, google for it
Sign up to request clarification or add additional context in comments.

2 Comments

how to do number 2 ?? when i already have my dbadapter.java ??
then it is good, just add your needed image path to your already created db, you can create new table into the already created db....

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.