0

I want to know how I can save an image in my storage because in my app I can take a photo and see it, but when I close my app and reopen it, the image disappears I have used bitmap.

My code:

public static final int REQUEST_CODE = 01;
private ImageView imgs1;
private File outputMediaFile;

protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.semana1);
     imgs1 = (ImageView) findViewById(R.id.imgs1);
}

public void btnTakePhotoClicked1(View v){
    Intent intent1= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent1, REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        Bitmap bm1= (Bitmap) data.getExtras().get("data");
        imgs1.setImageBitmap(bm1);
    }
} 

Jin Lee
  • 3,194
  • 12
  • 46
  • 86
spain
  • 1
  • 4

1 Answers1

0

Use this code in onActivityResult, after you have obtained the image bitmap object.

File file = new File("foldername/imagename.jpg")
OutputStream fOut = new FileOutputStream(file);
bm1.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();