我已经编写了自己的相机活动,我在FrameLayout
中显示了照片的实时预览,但实时图片看起来不自然,有点高,我认为这是因为{的尺寸{1}}与相机的尺寸不匹配。我该怎么做才能解决它?
以下是相机活动的xml文件:
FrameLayout
答案 0 :(得分: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);
}
答案 1 :(得分: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) ;