I’m using the following code to open the camera, take an image and display it in an imageview.
I assume on the onActivityResult I should be doing a bm.save type command but I can’t see one in there. Ideally i’d like to save it as a jpeg on the SD card.
Any help will be appreciated.
Tom
public class TakePhoto extends Activity {
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_photo);
iv = (ImageView) findViewById(R.id.imageView1);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Bitmap bm = (Bitmap) data.getExtras().get("data");
iv.setImageBitmap(bm);
}
}
This should do the trick. Call the following method with your Bitmap (that you took with your camera) and the filename of your choice eg. “myEpicPic”.
(I asume you know when you want/need to save the Bitmap)
And if you want to read the Bitmap from memory again:
I hope this helps.