gpt4 book ai didi

java - 安卓 : Camera's dimensions doesn't match screen's dimensions

转载 作者:行者123 更新时间:2023-12-01 14:49:05 28 4
gpt4 key购买 nike

我编写了自己的相机 Activity ,我在FrameLayout中显示照片的实时预览,但是实时图片看起来不自然,有点高,我认为这是因为尺寸FrameLayout 的尺寸与相机的尺寸不匹配。我应该做什么来修复它?

这是相机 Activity 的 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>

最佳答案

您必须缩放从相机拍摄的图像。你可以尝试这样的事情:

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);

}

关于java - 安卓 : Camera's dimensions doesn't match screen's dimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15062013/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com