Reputation: 3073
From my current search, Android camera intent can not specify pictureSize. Since my app needs to be fast, I do not want to save a large size picture in sd card, then load it to a small size of Bitmap. I think it takes time. Plus, I need a gray scale image, rather than a color Bitmap. I know how to convert them, but again it takes time.
I plan to take a picture at a specified size, and directly process the Y part (gray scale) in the YUV data in the memory.
So does that mean I have to write my own camera app using camera API?
Are there any good examples? Many examples I checked so far often do not consider autofocus. I add features in XML file:
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
I add the auto focus mode to the camera parameter.
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
But it does not work. So I add autofocus command immediately before camera press button.
preview.camera.autoFocus(myAutoFocusCallback);
preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
But the autofocus takes some time, and until the preview becomes clear, the take pictures has been performed. Plus, I also want it to autofocus even if I do not press the camera button. How can I put autofocus nicely in it?
Are there any good examples? Thanks.
Upvotes: 0
Views: 530
Reputation: 809
The Android Developers Guide has a tutorial on making a camera app: http://developer.android.com/guide/topics/media/camera.html#custom-camera
You don't need to add both the camera and the camera.autofocus features in the manifest. The latter implies the first - though it's not really a problem.
FOCUS_MODE_AUTO does not mean it the cameras will focus continuously, just that it will use autofocus at some point (instead of manual focus) by a callback function. You'll need FOCUS_MODE_CONTINUOUS_PICTURE if you want the camera focusing by itself. It's explained in the documentation.
As for taking pictures before the camera is focused: try calling takePicture() from inside your autoFocusCallback like this:
private AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
if (success) {
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
}
};
Upvotes: 2