I have the following code taking a picture and saving it. But I want to save the final image to SD card instead.
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");
writeBitmapToMemory("image.png", bm);
iv.setImageBitmap(bm);
}
public void writeBitmapToMemory(String filename, Bitmap bitmap) {
FileOutputStream fos;
try {
fos = this.openFileOutput(filename, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
Theres one bit that seems to be playing up. I'm trying to save to SD card but it falls over with an error: (pastebin.com/FHihS4Wv)
I changed writeBitmapToMemory("/mnt/extSdCard/image.png", bm);
on my onActivityResult –
But it falls over with the pastebinned error above