2013-02-22 53 views
0

我想爲android手機構建一個功能,打開CameraAPI,然後將捕獲的圖片發送到新的活動。CameraAPI打開後通過意圖發送圖像

在這個活動中,我需要它來顯示圖像的預覽,然後保存。

我怎麼能這樣做,而不必將圖像保存到SD卡?

+0

爲什麼你不想將它保存到SD卡?獲取照片的最簡單方法是使用startActivityForResult()並要求相機應用程序爲您完成工作,但這會將圖像保存到文件中。 – Clyde 2013-02-22 01:40:55

+0

這個想法是安全的,如果它在本地保存圖像可以抓住...以及從畫廊保存和查看。我的應用程序如果放在可能對使用它的人不利的錯誤手中。如果需要,政府也可以使用最高安全級別。 – Keeano 2013-02-22 06:06:51

+0

看看這個答案然後:http://stackoverflow.com/questions/4963581/how-to-capture-an-android-camera-image-without-saving-a-file-to-the-phone-sdcard – Clyde 2013-02-22 22:39:52

回答

0

您可以將影像存儲到一個位圖,然後將其轉換爲字節數組,然後通過這個代碼轉移到其他活動下

Bitmap bitmapPicture= "PICTURE FROM CAMERA"; 
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
bitmapPicture.compress(Bitmap.CompressFormat.JPEG, 40, bytes); 

然後通過意向

Intent imagepass = new Intent(Cam.this,Preview.class); 
imagepass.putExtra("imagepass", bytes.toByteArray()); 
startActivity(imagepass); 

在其他活動傳遞我們必須接收字節數組並轉換成位圖並在imageview中顯示通過

Bundle extras = getIntent().getExtras(); 
    byte[] byteArray = extras.getByteArray("imagepass"); 
    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); 

    ImageView iv=(ImageView) findViewById(R.id.imgvw2); 
    iv.setImageBitmap(bmp); 

你將不得不使用自定義攝像頭控制希望這有助於。