2012-10-17 135 views
1

我想實現一個應用程序,該應用程序將使用相機捕獲圖像並將其顯示在ImageView上。但是,系統會將圖像分辨率調整爲204x153,然後將其顯示在屏幕上,但它會將圖像的原始分辨率(3264x2448)保存在SD卡中。如何顯示原始尺寸的相機拍攝圖像?

這是我的代碼。

buttonCapture.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      Intent intentCamera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      bmpUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), 
        "pic_" + String.valueOf(System.currentTimeMillis()) + ".jpg")); 
      try { 
       intentCamera.putExtra("return-data", false); 
       startActivityForResult(intentCamera, resultOpenCamera); 
      } 
      catch (ActivityNotFoundException e) { 
       e.printStackTrace(); 
      }    
     } 
    }); 

和我的onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

     if (requestCode == resultOpenCamera && resultCode == RESULT_OK && null != data) { 
      setContentView(R.layout.preview); 

      if(data.getAction() != null){ 

       Uri selectedImage = data.getData(); 
       bmpUri = selectedImage; 
       // display image received on the view 
       Bundle newBundle = data.getExtras(); 
       Bitmap theImage = (Bitmap) newBundle.get("data"); 
       displayImage(preProcessing(theImage)); 
       System.out.println("theImage height n width = "+theImage.getHeight()+" + "+theImage.getWidth()); 
      } 
     } 
} 

我使用的System.out.println跟蹤位圖分辨率從攝像機捕獲。它表明只有204x153。原始分辨率應該是3264x2448。

任何人都知道如何解決這個問題? 非常感謝。

+0

請參考這個問題。它與此相似。 http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – Scorpion

回答

2

單從ACTION_IMAGE_CAPTURE官方文檔:

調用者可以通過一個額外的EXTRA_OUTPUT爲了控制這一形象 將被寫入。如果EXTRA_OUTPUT不存在,則在額外字段中將返回一個尺寸較小的圖像作爲位圖對象。這是 對於只需要小圖像的應用程序很有用。如果存在 EXTRA_OUTPUT,則全尺寸圖像將被寫入 EXTRA_OUTPUT的Uri值。

0

嘗試將imageview的縮放類型設置爲center或centerInside。

+0

是的,我試過這個。但取決於圖像本身的大小,從相機加載的圖像將自動縮小,因此仍然會顯示縮小圖像而不是全部圖像。 –

0

試試這個: -

int width = bmpSelectedImage.getWidth(); 
int height = bmpSelectedImage.getHeight(); 
float scaleWidth = ((float) 250)/width; 
float scaleHeight = ((float) 150)/height; 
Matrix matrix = new Matrix(); matrix.postRotate(90); 
resizedBitmap = Bitmap.createBitmap(bmpSelectedImage, 0, 0, width, height, matrix, true); 
+0

感謝您回答我的問題。 –

相關問題