Failed binder transaction when returning camera image


Last Updated:

  1. android88

    android88 Member This Topic's Starter

    Joined:
    Jan 6, 2010
    Messages:
    17
    Likes Received:
    0
    Hi, I get the Failed binder transaction error when returning the image taken with the camera from the camera intent back to the parent intent (as a byte[]). I don't understand why, its not like its a big bitmap or anything. It only happens when i take pictures with lots of light, because then the byte[] is bigger. Does anyone see a mistake in my code?

    Here is my code:

    Code (Text):
    1. package example.imaging.ape;
    2.  
    3. import java.io.IOException;
    4. import java.util.Iterator;
    5. import java.util.Set;
    6.  
    7. import android.app.Activity;
    8. import android.content.Intent;
    9. import android.graphics.Bitmap;
    10. import android.graphics.BitmapFactory;
    11. import android.graphics.PixelFormat;
    12. import android.hardware.Camera;
    13. import android.hardware.Camera.AutoFocusCallback;
    14. import android.os.Bundle;
    15. import android.util.Log;
    16. import android.view.MotionEvent;
    17. import android.view.SurfaceHolder;
    18. import android.view.SurfaceView;
    19. import android.view.View;
    20. import android.view.Window;
    21. import android.view.WindowManager;
    22. import android.view.View.OnTouchListener;
    23.  
    24. public class TakePicture extends Activity implements SurfaceHolder.Callback{
    25.     Camera mCamera;
    26.     Boolean mPreviewRunning = false;
    27.     int imageLayoutHeight;
    28.     int imageLayoutWidth;
    29.    
    30.     @Override
    31.     public void onCreate(Bundle savedInstanceState) {
    32.         super.onCreate(savedInstanceState);
    33.        
    34.         //setup camera surface
    35.         getWindow().setFormat(PixelFormat.TRANSLUCENT);
    36.         requestWindowFeature(Window.FEATURE_NO_TITLE);
    37.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    38.         setContentView(R.layout.cameralayout);
    39.  
    40.         SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.hist_surface_camera);
    41.         SurfaceHolder mSurfaceHolder = mSurfaceView.getHolder();
    42.         mSurfaceHolder.addCallback(this);
    43.         mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    44.         Bundle extras = getIntent().getExtras();
    45.         imageLayoutHeight = extras.getInt("layoutHeight");
    46.         imageLayoutWidth = extras.getInt("layoutWidth");
    47.        
    48.         OnTouchListener touchListener = new View.OnTouchListener() {
    49.             public boolean onTouch(View v, MotionEvent e) {
    50.  
    51.                 System.out.println("MAKING PICTURE");
    52.                 mCamera.autoFocus(cb);              
    53.                 return false;
    54.             }
    55.         };
    56.  
    57.         //setup touch listener
    58.         mSurfaceView.setOnTouchListener(touchListener);
    59.        
    60.     }
    61.    
    62.     AutoFocusCallback cb = new AutoFocusCallback() {
    63.         public void onAutoFocus(boolean success, Camera c) {
    64.             c.takePicture(null, null, mPictureCallback);
    65.         }    
    66.     };
    67.    
    68.     Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
    69.         public void onPictureTaken(byte[] imageData, Camera c) {
    70.             System.out.println("Picture taken, now returning");            
    71.             Intent resultIntent = new Intent();
    72.             resultIntent.putExtra("cameraImage", imageData);
    73.             System.out.println("put Extra");
    74.             setResult(Activity.RESULT_OK, resultIntent);
    75.             finish();            
    76.         }
    77.     };
    78.    
    79.     //initialize camera
    80.     public void surfaceCreated(SurfaceHolder holder) {
    81.         mCamera = Camera.open();
    82.     }
    83.  
    84.     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    85.         if (mPreviewRunning) {
    86.             mCamera.stopPreview();
    87.         }
    88.  
    89.         Camera.Parameters p = mCamera.getParameters();
    90.        
    91.         p.setPreviewSize(h, w);
    92.         System.out.println("PreviewSize: " + h + "," + w);
    93.         p.setPictureSize(h*3,w*3); // is around 1200x900
    94.         p.set("rotation", 90);
    95.         mCamera.setParameters(p);
    96.  
    97.         try {
    98.             mCamera.setPreviewDisplay(holder);
    99.         } catch (IOException e) {
    100.             e.printStackTrace();
    101.         }
    102.  
    103.         mCamera.startPreview();
    104.         mPreviewRunning = true;
    105.     }
    106.  
    107.     public void surfaceDestroyed(SurfaceHolder holder) {
    108.         mCamera.stopPreview();
    109.         mPreviewRunning = false;
    110.         mCamera.release();
    111.     }
    112.    
    113. }
     

    Advertisement

Share This Page

Loading...