Failed binder transaction when returning camera image

Put your problem here if it does not fit any of the other categories.

Failed binder transaction when returning camera image

Postby android88 » Sun Feb 14, 2010 5:14 pm

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package example.imaging.ape;
  2.  
  3.  
  4.  
  5. import java.io.IOException;
  6.  
  7. import java.util.Iterator;
  8.  
  9. import java.util.Set;
  10.  
  11.  
  12.  
  13. import android.app.Activity;
  14.  
  15. import android.content.Intent;
  16.  
  17. import android.graphics.Bitmap;
  18.  
  19. import android.graphics.BitmapFactory;
  20.  
  21. import android.graphics.PixelFormat;
  22.  
  23. import android.hardware.Camera;
  24.  
  25. import android.hardware.Camera.AutoFocusCallback;
  26.  
  27. import android.os.Bundle;
  28.  
  29. import android.util.Log;
  30.  
  31. import android.view.MotionEvent;
  32.  
  33. import android.view.SurfaceHolder;
  34.  
  35. import android.view.SurfaceView;
  36.  
  37. import android.view.View;
  38.  
  39. import android.view.Window;
  40.  
  41. import android.view.WindowManager;
  42.  
  43. import android.view.View.OnTouchListener;
  44.  
  45.  
  46.  
  47. public class TakePicture extends Activity implements SurfaceHolder.Callback{
  48.  
  49.         Camera mCamera;
  50.  
  51.         Boolean mPreviewRunning = false;
  52.  
  53.         int imageLayoutHeight;
  54.  
  55.         int imageLayoutWidth;
  56.  
  57.        
  58.  
  59.         @Override
  60.  
  61.         public void onCreate(Bundle savedInstanceState) {
  62.  
  63.                 super.onCreate(savedInstanceState);
  64.  
  65.                
  66.  
  67.                 //setup camera surface
  68.  
  69.                 getWindow().setFormat(PixelFormat.TRANSLUCENT);
  70.  
  71.                 requestWindowFeature(Window.FEATURE_NO_TITLE);
  72.  
  73.                 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  74.  
  75.                 setContentView(R.layout.cameralayout);
  76.  
  77.  
  78.  
  79.                 SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.hist_surface_camera);
  80.  
  81.                 SurfaceHolder mSurfaceHolder = mSurfaceView.getHolder();
  82.  
  83.                 mSurfaceHolder.addCallback(this);
  84.  
  85.                 mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  86.  
  87.                 Bundle extras = getIntent().getExtras();
  88.  
  89.                 imageLayoutHeight = extras.getInt("layoutHeight");
  90.  
  91.                 imageLayoutWidth = extras.getInt("layoutWidth");
  92.  
  93.                
  94.  
  95.                 OnTouchListener touchListener = new View.OnTouchListener() {
  96.  
  97.                         public boolean onTouch(View v, MotionEvent e) {
  98.  
  99.  
  100.  
  101.                                 System.out.println("MAKING PICTURE");
  102.  
  103.                                 mCamera.autoFocus(cb);                 
  104.  
  105.                                 return false;
  106.  
  107.                         }
  108.  
  109.                 };
  110.  
  111.  
  112.  
  113.                 //setup touch listener
  114.  
  115.                 mSurfaceView.setOnTouchListener(touchListener);
  116.  
  117.                
  118.  
  119.         }
  120.  
  121.        
  122.  
  123.         AutoFocusCallback cb = new AutoFocusCallback() {
  124.  
  125.                 public void onAutoFocus(boolean success, Camera c) {
  126.  
  127.                         c.takePicture(null, null, mPictureCallback);
  128.  
  129.                 }      
  130.  
  131.         };
  132.  
  133.        
  134.  
  135.         Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
  136.  
  137.                 public void onPictureTaken(byte[] imageData, Camera c) {
  138.  
  139.                         System.out.println("Picture taken, now returning");                    
  140.  
  141.                         Intent resultIntent = new Intent();
  142.  
  143.                         resultIntent.putExtra("cameraImage", imageData);
  144.  
  145.                         System.out.println("put Extra");
  146.  
  147.                         setResult(Activity.RESULT_OK, resultIntent);
  148.  
  149.                         finish();                      
  150.  
  151.                 }
  152.  
  153.         };
  154.  
  155.        
  156.  
  157.         //initialize camera
  158.  
  159.         public void surfaceCreated(SurfaceHolder holder) {
  160.  
  161.                 mCamera = Camera.open();
  162.  
  163.         }
  164.  
  165.  
  166.  
  167.         public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
  168.  
  169.                 if (mPreviewRunning) {
  170.  
  171.                         mCamera.stopPreview();
  172.  
  173.                 }
  174.  
  175.  
  176.  
  177.                 Camera.Parameters p = mCamera.getParameters();
  178.  
  179.                
  180.  
  181.                 p.setPreviewSize(h, w);
  182.  
  183.                 System.out.println("PreviewSize: " + h + "," + w);
  184.  
  185.                 p.setPictureSize(h*3,w*3); // is around 1200x900
  186.  
  187.                 p.set("rotation", 90);
  188.  
  189.                 mCamera.setParameters(p);
  190.  
  191.  
  192.  
  193.                 try {
  194.  
  195.                         mCamera.setPreviewDisplay(holder);
  196.  
  197.                 } catch (IOException e) {
  198.  
  199.                         e.printStackTrace();
  200.  
  201.                 }
  202.  
  203.  
  204.  
  205.                 mCamera.startPreview();
  206.  
  207.                 mPreviewRunning = true;
  208.  
  209.         }
  210.  
  211.  
  212.  
  213.         public void surfaceDestroyed(SurfaceHolder holder) {
  214.  
  215.                 mCamera.stopPreview();
  216.  
  217.                 mPreviewRunning = false;
  218.  
  219.                 mCamera.release();
  220.  
  221.         }
  222.  
  223.        
  224.  
  225. }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4
android88
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Jan 05, 2010 9:06 pm

Top

Postby j 2 the b » Fri Mar 19, 2010 9:24 pm

Hi,
I was facing the same problem. The only solution I consider is to compress the image:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         BitmapFactory.Options options = new BitmapFactory.Options();
  2.  
  3.                         options.inSampleSize = 2;
  4.  
  5.  
  6.  
  7.                         Bitmap temp_image = BitmapFactory.decodeByteArray(data, 0, data.length, options);
  8.  
  9.                    
  10.  
  11.                         ByteArrayOutputStream out =  new ByteArrayOutputStream();
  12.  
  13.                         temp_image.compress(CompressFormat.JPEG, 60, out);
  14.  
  15.                         byte[] temp_data = out.toByteArray();
  16.  
  17.                    
  18.  
  19.                    Intent intent = new Intent();
  20.  
  21.                    intent.putExtra("image_data", temp_data);
  22.  
  23.                    setResult(SUCCESS_RETURN_CODE_IMAGE,  intent);
  24.  
  25.  
  26.  
  27.                PictureCapturer.this.finish();
Parsed in 0.045 seconds, using GeSHi 1.0.8.4

Hope it helps.
j 2 the b
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Mar 19, 2010 9:20 pm

Re: Failed binder transaction when returning camera image

Postby droidoine » Mon Mar 19, 2012 11:13 am

Had the same problem. Converted picture, now it works perfectly. But i registered some errors in the post before. The method should look like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  Camera.PictureCallback mPictureCallback = new Camera.PictureCallback(){
  2.       public void onPictureTaken(byte[] imageData, Camera c) {
  3.  
  4.           if (imageData != null) {
  5.  
  6.                  //StoreByteImage(mContext, imageData, 50, "ImageName");
  7.              
  8.               BitmapFactory.Options options = new BitmapFactory.Options();
  9.               options.inSampleSize = 2;
  10.  
  11.               Bitmap temp_image = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);
  12.  
  13.               ByteArrayOutputStream out =  new ByteArrayOutputStream();
  14.               temp_image.compress(CompressFormat.JPEG, 60, out);
  15.               byte[] temp_data = out.toByteArray();
  16.  
  17.               Intent intent = new Intent();
  18.               intent.putExtra("image_data", temp_data);
  19.               setResult(FOTO_MODE,  intent);
  20.  
  21.               CameraActivity.this.finish();
  22.  
  23.           }
  24.       }
  25.   };
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
droidoine
Freshman
Freshman
 
Posts: 2
Joined: Mon Mar 19, 2012 10:35 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 19 guests