简体   繁体   English

调整相机预览的大小

[英]Resizing the Camera Preview

I have implemented a camera application, which will show the preview in the entire screen of the device. 我已经实现了一个相机应用程序,它将在设备的整个屏幕上显示预览。 But my requirement is to show the Camera preview in a small screen. 但我的要求是在小屏幕上显示相机预览。 My device resolution is 800x480(WxH) ie, Nexus one. 我的设备分辨率是800x480(WxH),即Nexus one。 I can able to show the preview in the entire screen without scale down the preview. 我可以在整个屏幕上显示预览,而无需缩小预览。 Its coming perfectly, but when i try show the preview in small screens(part of my total mobile screen), the preview is getting stretched and not looking good. 它完美无缺,但是当我尝试在小屏幕(我的整个手机屏幕的一部分)中显示预览时,预览会变得紧张而且看起来不太好。

Is there any way to show the preview correctly in a small screen. 有没有办法在小屏幕上正确显示预览。 I think we need to scale down the image preview. 我认为我们需要缩小图像预览。 But when i try to scale down the image preview, the android system itself doesn't allowing to set the scaled preview size. 但是当我尝试缩小图像预览时,android系统本身不允许设置缩放的预览大小。

Could any one please help me how to scale the image preview in small screen. 任何人都可以帮我如何在小屏幕上缩放图像预览。

After struggling with this same problem for about a week, I was FINALLY able to get the camera preview to resize itself programmatically! 在经历了大约一个星期的同样问题之后,我终于可以通过编程方式让相机预览自行调整大小! :-D :-D

preview is the name of my SurfaceView and in this code, I have it set up so that it resizes itself to be half of the width of the RelativeLayout that it's in. preview是我的SurfaceView的名称,在这段代码中,我设置它,以便它自己调整为它所在的RelativeLayout宽度的一半。

ViewGroup.LayoutParams params = preview.getLayoutParams();
RelativeLayout myRelLayout = (RelativeLayout) findViewById(R.id.myRelLayout);
params.width = (int) (myRelLayout.getWidth()/2);
preview.setLayoutParams(params);

Now for your use, you will need to look at the resolution of the preview and then scale down the height or width accordingly based on that resolution. 现在供您使用,您需要查看预览的分辨率,然后根据该分辨率相应地缩小高度或宽度。

uday, 乌代,

Have you tried just changing 你试过改变吗?

<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/ButtonGroup"
        />

to something like this.... 这样的事......

<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/preview"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_above="@id/ButtonGroup"
        />

if that's not what you're looking for, maybe you could post your current code so we can take a look at it? 如果这不是您想要的,也许您可​​以发布您当前的代码,以便我们可以看看它? :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM