gpt4 book ai didi

android - 拍照,然后将图片放在 ImageView 上。试图让它全屏,但我无法弄清楚。

转载 作者:行者123 更新时间:2023-11-30 02:13:41 25 4
gpt4 key购买 nike

标题解释得很好。我成功地拍了一张照片,然后将该字节数组转换为 bmp,然后将 bmp 放在 应该 全屏的 ImageView 上。但它太小了。

The ImageView (which is supposed to be full screen) on top of the camera preview

该图片是预览顶部的 ImageView(分配了我刚拍摄的图片)。这是相关的代码。

Camera.PictureCallback jpgCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
ImageView image = (ImageView) findViewById(R.id.picPreview);
image.setImageBitmap(bmp);
image.setRotation(90);
image.setVisibility(View.VISIBLE);
}
};

<SurfaceView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/surfaceView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Picture"
android:id="@+id/takePicButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#ff6cafff"
android:textAlignment="center"
android:enabled="true"
android:onClick="takePic"/>

<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/picPreview"
android:layout_alignParentBottom="true"
android:visibility="invisible"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>

我已经尝试将 scaleType 更改为 center、centerCrop、default 等,但没有使图片全屏显示。

有人知道我需要做什么吗?

最佳答案

我怀疑问题是您的图像分辨率不是很高。 ImageView 将尽其所能定位您的内容,但不会修改内容本身。在这种情况下,picPreview View 可能正确填充父容器,但图像太小,因此居中且未拉伸(stretch)。

例如,您的屏幕可能是 1920x1080,而该图片只有 1280x720。默认情况下,ImageView 不会拉伸(stretch)图像。

尝试将此添加到您的 Activity 代码中:

  ImageView imgView = (ImageView) findViewById(R.id.picPreview)
imgView.setScaleType(ScaleType.FIT_XY);

关于android - 拍照,然后将图片放在 ImageView 上。试图让它全屏,但我无法弄清楚。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29736452/

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