2013-03-12 42 views
3

我正在嘗試拍攝照片應用程序。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(); 
} 

代碼

; 異常被扔

「源未找到」

有什麼不對?

回答

1

您可以在進程(您的案例中的活動)之間傳遞有限數量的數據。代替傳遞字節數組本身,請將您的字節數組(圖像)保存爲文件,並將路徑傳遞給該文件(例如,URI爲ContentProvider)。