2013-02-25 264 views
0

我已經編寫了自己的相機活動,我在FrameLayout中展示了該照片的實時預覽,但實況圖像看起來並不自然,有點高,我認爲它是因爲FrameLayout的尺寸與相機尺寸不符。我應該怎麼做才能解決它?Android:相機的尺寸與屏幕尺寸不匹配

這裏是相機活動的xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

<FrameLayout 
    android:id="@+id/camera_preview" 
    android:layout_width="wrap_content" 
    android:layout_height="0dip" 
    android:layout_weight="0.86" /> 

<Button 
    android:id="@+id/button_capture" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="16dp" 
    android:gravity="center" 
    android:onClick="capture" 
    android:text="Capture" /> 

<Button 
    android:id="@+id/button_accept" 
    android:layout_width="115dp" 
    android:layout_height="wrap_content" 
    android:text="Accept" 
    android:visibility="gone" 
    android:onClick = "accept" /> 

<Button 
    android:id="@+id/button_retake" 
    android:layout_width="107dp" 
    android:layout_height="wrap_content" 
    android:text="Retake" 
    android:visibility="gone" 
    android:onClick = "retake"/> 

</LinearLayout> 

回答

0

的問題是可以解決這樣的:

 Parameters cameraParam = mCamera.getParameters() ; 
     double ratio = (double)cameraParam.getPictureSize().height/(double)cameraParam.getPictureSize().width ; 
     Display display = getWindowManager().getDefaultDisplay(); 
     Point size = new Point(); 
     try 
     { 
      display.getSize(size); 
     } 
     catch(java.lang.NoSuchMethodError ignore) 
     { 
      size.x = display.getWidth(); 
      size.y = display.getHeight() ; 
     } 
     int width = size.y; 
     int height = size.x; 
     previewParam.width = width; 
     previewParam.height = (int)(previewParam.width/ratio) ; 
1

你將不得不規模已經從相機拍攝的圖像。你可以嘗試這樣的事:

private Bitmap scaleImage(ImageView imageView, String path) { 
int targetWidth = imageView.getWidth(); 
int targetHeight = imageView.getHeight(); 

BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); 
bitmapOptions.inJustDecodeBounds = true; 
BitmapFactory.decodeFile(path, bitmapOptions); 
int photoWidth = bitmapOptions.outWidth; 
int photoHeight = bitmapOptions.outHeight; 

int scaleFactor = Math.min(photoWidth/targetWidth, photoHeight/targetHeight); 

bitmapOptions.inJustDecodeBounds = false; 
bitmapOptions.inSampleSize = scaleFactor; 
bitmapOptions.inPurgeable = true; 

return BitmapFactory.decodeFile(path, bitmapOptions); 

}

+0

沒有,已經從照相機拍攝的照片是好的,只是現場圖片在相機預覽中顯示(拍攝照片之前)有點高! – Navid777 2013-02-25 12:11:00

+0

是你的代碼打開相機類似於: 意圖cameraIntent =新的意圖(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); getActivity()。startActivityForResult(cameraIntent,IMAGE_CAPTURE_REQUEST_CODE); – lokoko 2013-02-25 12:25:34

+0

不,我寫了我自己的相機活動 – Navid777 2013-02-25 12:37:22