我正在尝试制作拍照应用程序。
在主要活动中有surfaceview作为预览和按钮“拍照”。 在第二个活动上有一些图片信息的textView和用于显示图片的imageView;
我试图通过putExtra()方法传输数据。
关于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();
}
关于接收活动
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开始时 picture = i.getByteArrayExtra(“pic”); 抛出异常
“找不到来源”
出了什么问题?
答案 0 :(得分:1)
您可以在进程之间传递有限数量的数据(在您的情况下为活动)。而不是传递字节数组本身,将您的字节数组(图像)保存为文件,并将路径传递给该文件(例如,ContentProvider
的URI)。