gpt4 book ai didi

java/android不能在activity之间传递byte数组

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:48 24 4
gpt4 key购买 nike

我正在尝试制作一个拍照应用程序。

主要 Activity 上有作为预览的表面 View 和“拍照”按钮。在第二个 Activity 中,有一些图片信息的 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();
}

关于接收 Activity

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);
}
}

当调试器启动时 图片 = i.getByteArrayExtra("图片");抛出异常

“找不到来源”

怎么了?

最佳答案

您可以在流程(您的案例中的 Activity )之间传递有限数量的数据。不是传递字节数组本身,而是将字节数组(图像)保存为文件并传递到该文件的路径(例如 ContentProvider 的 URI)。

关于java/android不能在activity之间传递byte数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15356014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com