Wednesday, 21 August 2013

What's wrong with my code? Camera app not saving pictures

What's wrong with my code? Camera app not saving pictures

I'm programming a camera app and it lets me see the camera and snap the
photo and everything but for some reason it doesn't save. Also I'd like
the picture to stay for a few seconds after taken before going back to
camera mode. Can someone please tell me what's wrong with my code?
Thanks so much!!
AndroidManifest:
<uses-feature android:name="android.hardware.camera"
android:required="true"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="WRITE_INTERNAL_STORAGE"/>
MainActivity.java:
@Override
public void onPictureTaken(byte[] data, Camera camera) {
//Here, we chose internal storage
try {
FileOutputStream out = openFileOutput("picture.jpg",
Activity.MODE_PRIVATE);
out.write(data);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
camera.startPreview();
}

No comments:

Post a Comment