Java/android无法在活动之间传输字节数组
问题描述:
我正在尝试拍摄照片应用程序。Java/android无法在活动之间传输字节数组
有表面视图作为预览和主要活动的“拍照”按钮。 第二个活动有textView的一些图片信息和imageView用于显示图片;
我试图通过putExtra()方法传输数据。
上的recieving活动public class recognized extends Activity
{
int score;
int leye_x, leye_y;
int reye_x, reye_y;
int mouth_x, mouth_y;
int r_bottom, r_top, r_left, r_right;
byte[] picture;
TextView tvFaceInfo;
ImageView ivFaceDisplay;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.recognized);
Intent i = getIntent();
tvFaceInfo = (TextView) findViewById(R.id.tvFaceInfo);
ivFaceDisplay = (ImageView) findViewById(R.id.ivFacePicture);
score = i.getIntExtra("score", -1);
r_bottom = i.getIntExtra("rect_bottom" , -1);
r_right = i.getIntExtra("rect_right" , -1);
r_left = i.getIntExtra("rect_left" , -1);
r_top = i.getIntExtra("rect_top" , -1);
picture = i.getByteArrayExtra("pic");// getByteArrayExtra("picture");
Bitmap bm = BitmapFactory.decodeByteArray(picture, 0, 1280*960);
//bm.copyPixelsFromBuffer(picture);
ivFaceDisplay.setImageBitmap(bm);
tvFaceInfo.setText("score: " + score + "\n"
+ "rect " + r_bottom + " " + r_right + " " + r_left + " " + r_top);
}
}
当debuger上 图象= i.getByteArrayExtra( “PIC”)获取mainActivity
public void onPictureTaken(byte[] data, Camera camera)
{
// TODO Auto-generated method stub
RecognizedActivity = new Intent(MainActivity.this, recognized.class);
RecognizedActivity.putExtra("score", rFace.score);
//RecognizedActivity.putExtra("leyex", rFace.leftEye.x);
//RecognizedActivity.putExtra("leyex", rFace.leftEye.x);
/*RecognizedActivity.putExtra("leye_y", rFace.leftEye.y);
RecognizedActivity.putExtra("reye_x", rFace.rightEye.x);
RecognizedActivity.putExtra("reye_y", rFace.rightEye.y);
RecognizedActivity.putExtra("mouth_x", rFace.mouth.x);
RecognizedActivity.putExtra("mouth_y", rFace.mouth.y);
*/
RecognizedActivity.putExtra("rect_bottom" , rFace.rect.bottom);
RecognizedActivity.putExtra("rect_right" , rFace.rect.right);
RecognizedActivity.putExtra("rect_left" , rFace.rect.left);
RecognizedActivity.putExtra("rect_top" , rFace.rect.top);
//RecognizedActivity.putExtra("picture", data);
RecognizedActivity.putExtra("pic", data);
startActivity(RecognizedActivity);
cam.startPreview();
}
代码
; 异常被扔
“源未找到”
有什么不对?
答
您可以在进程(您的案例中的活动)之间传递有限数量的数据。代替传递字节数组本身,请将您的字节数组(图像)保存为文件,并将路径传递给该文件(例如,URI为ContentProvider
)。