Reputation: 3681
I've written my own camera activity, I show the photo's live preview in a FrameLayout
, but the live picture doesn't seem natural, it's a bit tall, I think it's because the dimensions of the FrameLayout
doesn't match the camera's dimensions. what should I do to fix it ?
Here is the xml file of the camera activity :
<?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>
Upvotes: 0
Views: 247
Reputation: 3681
the problem can be solved like this :
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) ;
Upvotes: 0
Reputation: 5803
You would have to scale the image that has been taken from the camera. You could try something like this :
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);
}
Upvotes: 1