This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection. Click here to get a chronological list of all published articles about Instant Mustache.
Writing the PhotoActivity
We'll start by creating an empty activity called PhotoActivity and add it to the manifest of our application. For now the layout will only contain an ImageView to display the picture:
activity_photo.xml |
Instead of showing a toast in our CameraActivity we create an Intent to start the PhotoActivity and use setData(Uri) on the Intent object to pass a Uri pointing to the picture file:
onPictureTaken() - CameraActivity.java |
In onCreate(Bundle) of the PhotoActivity we'll retrieve the Uri from the Intent and pass it to the ImageView. The ImageView will take care of loading the picture from the external storage and displaying it.
onCreate() - PhotoActivity.java |
And that's already all the code we need for the first version of the PhotoActivity.
CameraActivity (left) and PhotoActivity (right) |
How about utilising one of the popular pinch/zoom open source libraries on the photo activity? A photo isn't really a photo without pinch 'n zoom.
ReplyDeleteI recall a couple of weeks ago the Android office hours (uk version) were talking to a guy in the hangout called Chris... (second name escapes me) and were singing praises about the pinch zoom library he'd published.
Thanks martin! As said on Google plus: Yeah, Pinch-to-Zoom could be a good enhancement for a future version. Let's see what camera/gallery features are missed the most after the first release.
ReplyDeleteThanks for the Blog!! It is very resourceful!! I have always struggling on some camera API problem, and this blog provides all the solution!! keep it up!!
ReplyDelete