Last active
April 23, 2017 19:05
-
-
Save MichaelObi/58fc52ecb44c8d9c212dab9bd2233ec2 to your computer and use it in GitHub Desktop.
Save photo from a Camera source to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void takePhoto() { | |
mCameraSource.takePicture(null, new CameraSource.PictureCallback() { | |
@Override | |
public void onPictureTaken(byte[] bytes) { | |
try { | |
File basePath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "vstyle"); | |
if (!basePath.exists()) { | |
Log.d("CAPTURE_BASE_PATH", basePath.mkdirs() ? "Success": "Failed"); | |
} | |
File captureFile = new File(basePath + "photo_" + (new Date().getTime()) + ".jpg"); | |
if (!captureFile.exists()) | |
Log.d("CAPTURE_FILE_PATH", captureFile.createNewFile() ? "Success": "Failed"); | |
FileOutputStream stream = new FileOutputStream(captureFile); | |
stream.write(bytes); | |
stream.flush(); | |
stream.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment