0

I get a green screen with the front camera from samsung galaxy s, but the preview is correct. With the Back-Camera can I make photos.

Where is the problem?

This is my PictureCallback:

    public void onIvButtonShutterClick(View view) {

    PictureCallback pictureCallback = new PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            try {
                File picture = new File(My_Camera.this.getFilesDir()
                        + "/bild.jpg");
                FileOutputStream pictureOut = new FileOutputStream(picture);
                pictureOut.write(data);
                pictureOut.flush();
                pictureOut.close();
                Toast.makeText(
                        My_Camera.this,
                        getResources().getString(
                                R.string.tx_my_camera_save)
                                + "\n" + picture.getAbsolutePath(),
                        Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
            //mCamera.startPreview(); // Preview wird weiter ausgeführt
        }
    };

    mCamera.takePicture(null, null, pictureCallback);
}

I access on the front camera with:

    @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {

        mParameters = mCamera.getParameters();

        mParameters.set("camera-id", 2);
        mParameters.setPictureFormat(PixelFormat.JPEG);
        mCamera.setDisplayOrientation(270);
        mCamera.setParameters(mParameters);
        mCamera.startPreview();
}
Oli
  • 1,407
  • 3
  • 30
  • 47

3 Answers3

1

I had the same problem but never found a real solution.

What I ended up using was to grab frames from the camera preview. This has some issues – like, pictures are much more likely to be blurry.

The relevant method for grabbing preview frames is Camera.setOneShotPreviewCallback.

mrb
  • 3,281
  • 1
  • 20
  • 31
  • yes I have the same solution. If you find a better solution. Let me know ;-)..... – Oli May 23 '11 at 09:17
0

I think the problem might be the processing of the result. I'm guessing you are sending the originally captured byte array containing the raw image data to a file with jpg extension, but the byte array is not in jpg data (i.e. missing headers and with uncompressed content). Here's a relevant piece from some code I have (the MeToo project that you saw), imageData being the raw content:

        Bitmap backCameraImage = BitmapFactory.decodeByteArray(imageData,
                0, imageData.length).copy(Bitmap.Config.RGB_565, true);
        FileOutputStream out = null;
        out = new FileOutputStream(file);
        backCameraImage.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.close();

Hope this helps...

loxai
  • 1
  • I still get the error :-(... This is my Logcat: ERROR/SecCamera(11475): ERR(fimc_v4l2_g_ctrl):VIDIOC_G_CTRL failed ERROR/SecCamera(11475): cancelAutofocus(): getAutoFocusResult() is failed ERROR/SecCamera(11475): cancelAutofocus() end, 0, -1 ERROR/SecCamera(11475): stopPreview() ERROR/SecCamera(11475): fimc_v4l2_streamoff() ERROR/CameraHardwareSec(11475): stopPreview() end – Oli Apr 11 '11 at 11:54
  • and you say the same code works fine for the back camera, that is, if you comment out mParameters.set("camera-id",2); it takes a picture correctly? – loxai Apr 11 '11 at 17:31
  • I don't see why would it work for one camera and not the other one... I'd suggest playing with the stop and start preview requests, as I remember that giving me some trouble... (and make sure you stop before changing parameters) – loxai Apr 11 '11 at 18:21
  • Yes the same code works fine for the back camera. Here is my sample code: http://www.megaupload.com/?d=COH7HCJJ maybe you find the error...Thank you! – Oli Apr 12 '11 at 10:45
  • I'm afraid I can't find the source of the problem... here's a few things you can try: - move the callback code declaration to class level. - set the autofocus parameter to false (the error says something about that). - make sure stopPreview() is not called between onShutterClick() and onPictureTaken(). I can mail you my code to access the front camera, but it's a bit of a mess... – loxai Apr 12 '11 at 11:52
  • Thank you! PreviewCallback works fine... http://stackoverflow.com/questions/4768165/android-problem-whith-converting-preview-frame-to-bitmap – Oli Apr 14 '11 at 09:26
0

Did you try to set this parameter:

mParameters.setPreviewFormat(PixelFormat.JPEG);

It helped me, but on Motorola Droid causing problems.

dikirill
  • 1,873
  • 1
  • 19
  • 21