2016-10-25 116 views
6

比較很簡單:我使用使用CameraManager的自定義相機拍攝照片。然後我使用默認的Galaxy Note 5相機拍攝相同的照片。 CameraManager可用的最大尺寸爲3264 by 1836,所以我使用它並將三星相機設置爲相同的分辨率。結果如何增加使用CameraManager拍攝的照片的質量

  • 注5:我可以看到細節照片
  • CameraManager:我無法看到的細節。圖像質量不高。

然後我試着用

captureBuilder.set(CaptureRequest.JPEG_QUALITY, (byte) 100); 

仍然沒有改變設置CameraManager照片。那麼只有一個變化:使用CameraManager拍攝的照片的文件大小變爲2.3MB(它曾經是0.5MB),而三星照片的大小(保留)爲1.6MB。因此,即使尺寸較大,使用CameraManager拍攝的照片質量仍然較差。任何想法我可以解決這個問題:我如何使CameraManager拍攝的照片具有與Note 5附帶的默認Camera應用程序拍攝的照片相同的質量?

+0

另外那爲什麼三星相機可以達到'5312x2088'而CameraManager通過1836'報告的'3264一個最大? –

+0

你使用普通的'android.hardware.Camera'類嗎? – nandsito

+0

抱歉延遲。我正在使用'android.hardware.camera2' –

回答

0

我認爲質量在三星相機應用程序更好,因爲它使用Samsung Camera SDK。它是Camera2 API的擴展。

SDK提供了有用的附加功能(例如相位自動對焦)。嘗試啓用鏡頭光學穩定。

1

這些是我們在Camer管理器上工作時的一些方法,這種方法 可能會對您有所幫助。

Android相機應用編碼在Intent 照片作爲額外小的位圖傳遞到onActivityResult(), 下鍵「數據」。以下代碼檢索此圖像並在ImageView中顯示 。

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { 
      Bundle extras = data.getExtras(); 
      Bitmap imageBitmap = (Bitmap) extras.get("data"); 
      mImageView.setImageBitmap(imageBitmap); 
     } 
    } 
    private File createImageFile() throws IOException { 
     // Create an image file name 
     String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
     String imageFileName = "JPEG_" + timeStamp + "_"; 
     File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); 
     File image = File.createTempFile(
      imageFileName, /* prefix */ 
      ".jpg",   /* suffix */ 
      storageDir  /* directory */ 
     ); 

     // Save a file: path for use with ACTION_VIEW intents 
     mCurrentPhotoPath = "file:" + image.getAbsolutePath(); 
     return image; 
    } 
private void setPic() { 
    // Get the dimensions of the View 
    int targetW = mImageView.getWidth(); 
    int targetH = mImageView.getHeight(); 

    // Get the dimensions of the bitmap 
    BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
    bmOptions.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); 
    int photoW = bmOptions.outWidth; 
    int photoH = bmOptions.outHeight; 

    // Determine how much to scale down the image 
    int scaleFactor = Math.min(photoW/targetW, photoH/targetH); 

    // Decode the image file into a Bitmap sized to fill the View 
    bmOptions.inJustDecodeBounds = false; 
    bmOptions.inSampleSize = scaleFactor; 
    bmOptions.inPurgeable = true; 

    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); 
    mImageView.setImageBitmap(bitmap); 
}