Android 返回相机图像时绑定器事务失败

Android 返回相机图像时绑定器事务失败,android,Android,当将相机拍摄的图像从相机意图返回到父意图时,我在logcat中得到失败的活页夹事务错误(使用putExtra作为字节[])。我不明白为什么,它不像是一个大位图或任何东西。只有在光线充足的情况下拍照时才会发生这种情况,因为这样一来字节[]就更大了。离开相机时发生错误。有人看到我的代码中有错误吗 以下是摄像机意图的代码: package example.imaging.ape; import java.io.IOException; import java.util.Iterator; impor

当将相机拍摄的图像从相机意图返回到父意图时,我在logcat中得到失败的活页夹事务错误(使用putExtra作为字节[])。我不明白为什么,它不像是一个大位图或任何东西。只有在光线充足的情况下拍照时才会发生这种情况,因为这样一来字节[]就更大了。离开相机时发生错误。有人看到我的代码中有错误吗

以下是摄像机意图的代码:

package example.imaging.ape;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;

public class TakePicture extends Activity implements SurfaceHolder.Callback{
     Camera mCamera;
     Boolean mPreviewRunning = false;
     int imageLayoutHeight;
     int imageLayoutWidth;

     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          //setup camera surface
          getWindow().setFormat(PixelFormat.TRANSLUCENT);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.cameralayout);

          SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.hist_surface_camera);
          SurfaceHolder mSurfaceHolder = mSurfaceView.getHolder();
          mSurfaceHolder.addCallback(this);
          mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          Bundle extras = getIntent().getExtras();
          imageLayoutHeight = extras.getInt("layoutHeight");
          imageLayoutWidth = extras.getInt("layoutWidth");

          OnTouchListener touchListener = new View.OnTouchListener() {
               public boolean onTouch(View v, MotionEvent e) {

                    System.out.println("MAKING PICTURE");
                    mCamera.autoFocus(cb);             
                    return false;
               }
          };

          //setup touch listener
          mSurfaceView.setOnTouchListener(touchListener);

     }

     AutoFocusCallback cb = new AutoFocusCallback() {
          public void onAutoFocus(boolean success, Camera c) {
               c.takePicture(null, null, mPictureCallback);
          }   
     };

     Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
          public void onPictureTaken(byte[] imageData, Camera c) {
               System.out.println("Picture taken, now returning");              
               Intent resultIntent = new Intent();
               resultIntent.putExtra("cameraImage", imageData);
               System.out.println("put Extra");
               setResult(Activity.RESULT_OK, resultIntent);
               finish();           
          }
     };

     //initialize camera
     public void surfaceCreated(SurfaceHolder holder) {
          mCamera = Camera.open();
     }

     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
          if (mPreviewRunning) {
               mCamera.stopPreview();
          }

          Camera.Parameters p = mCamera.getParameters();

          p.setPreviewSize(h, w);
          System.out.println("PreviewSize: " + h + "," + w);
          p.setPictureSize(h*3,w*3); // is around 1200x900
          p.set("rotation", 90);
          mCamera.setParameters(p);

          try {
               mCamera.setPreviewDisplay(holder);
          } catch (IOException e) {
               e.printStackTrace();
          }

          mCamera.startPreview();
          mPreviewRunning = true;
     }

     public void surfaceDestroyed(SurfaceHolder holder) {
          mCamera.stopPreview();
          mPreviewRunning = false;
          mCamera.release();
     }

}
Intent intent = new Intent(Example.this, TakePicture.class);
intent.putExtra("layoutWidth",layoutWidth);
intent.putExtra("layoutHeight",layoutHeight);                   
startActivityForResult(intent,0);
下面是调用摄影机意图的代码:

package example.imaging.ape;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;

public class TakePicture extends Activity implements SurfaceHolder.Callback{
     Camera mCamera;
     Boolean mPreviewRunning = false;
     int imageLayoutHeight;
     int imageLayoutWidth;

     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          //setup camera surface
          getWindow().setFormat(PixelFormat.TRANSLUCENT);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.cameralayout);

          SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.hist_surface_camera);
          SurfaceHolder mSurfaceHolder = mSurfaceView.getHolder();
          mSurfaceHolder.addCallback(this);
          mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          Bundle extras = getIntent().getExtras();
          imageLayoutHeight = extras.getInt("layoutHeight");
          imageLayoutWidth = extras.getInt("layoutWidth");

          OnTouchListener touchListener = new View.OnTouchListener() {
               public boolean onTouch(View v, MotionEvent e) {

                    System.out.println("MAKING PICTURE");
                    mCamera.autoFocus(cb);             
                    return false;
               }
          };

          //setup touch listener
          mSurfaceView.setOnTouchListener(touchListener);

     }

     AutoFocusCallback cb = new AutoFocusCallback() {
          public void onAutoFocus(boolean success, Camera c) {
               c.takePicture(null, null, mPictureCallback);
          }   
     };

     Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
          public void onPictureTaken(byte[] imageData, Camera c) {
               System.out.println("Picture taken, now returning");              
               Intent resultIntent = new Intent();
               resultIntent.putExtra("cameraImage", imageData);
               System.out.println("put Extra");
               setResult(Activity.RESULT_OK, resultIntent);
               finish();           
          }
     };

     //initialize camera
     public void surfaceCreated(SurfaceHolder holder) {
          mCamera = Camera.open();
     }

     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
          if (mPreviewRunning) {
               mCamera.stopPreview();
          }

          Camera.Parameters p = mCamera.getParameters();

          p.setPreviewSize(h, w);
          System.out.println("PreviewSize: " + h + "," + w);
          p.setPictureSize(h*3,w*3); // is around 1200x900
          p.set("rotation", 90);
          mCamera.setParameters(p);

          try {
               mCamera.setPreviewDisplay(holder);
          } catch (IOException e) {
               e.printStackTrace();
          }

          mCamera.startPreview();
          mPreviewRunning = true;
     }

     public void surfaceDestroyed(SurfaceHolder holder) {
          mCamera.stopPreview();
          mPreviewRunning = false;
          mCamera.release();
     }

}
Intent intent = new Intent(Example.this, TakePicture.class);
intent.putExtra("layoutWidth",layoutWidth);
intent.putExtra("layoutHeight",layoutHeight);                   
startActivityForResult(intent,0);

由于某些原因,Android不喜欢您尝试传递原始字节[]数组或由此创建的位图。有些人已经成功地压缩了生成的位图并通过Intent传递了它。我建议先将图像保存到文件中,然后通过Intent发送其路径。

在远程过程调用期间,调用的参数和返回值作为存储在活页夹事务缓冲区中的地块对象进行传输。如果参数或返回值太大,无法放入事务缓冲区,则调用将失败,并引发TransactionTooLargeException


请参阅此链接表单

Emulator在意图中丢失了内存加载属性,因此出现异常

您是否曾经使其正常工作过?我也遇到同样的问题。请确保返回的数据是正确的false@hunterp你说那个猎人是什么意思?我有这个问题,需要解决它。