调整相机preVIEW相机、preVIEW

2023-09-05 06:18:11 作者:姐就是拽

我已实施了照相机的应用程序,这将显示preVIEW在设备的整个屏幕。但我的要求是,以显示相机preVIEW在一个小屏幕。我的设备分辨率为800×480(宽x高)即Nexus手机。我也能呈现preVIEW在整个屏幕,比例放倒了preVIEW。其未来的完美,但是当我尝试显示小屏幕的preVIEW(我的总手机屏幕的一部分),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) i.e, 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.

有没有什么办法可以正确显示preVIEW在一个小屏幕。我认为我们需要缩小图像preVIEW。但是,当我尝试缩小图像preVIEW,Android系统本身并没有允许设置缩放preVIEW大小。

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.

可能任何一个请帮助我如何缩放图像preVIEW在小屏幕上。

Could any one please help me how to scale the image preview in small screen.

推荐答案

与此相同的问题挣扎大约一个星期后,我终于能够让相机preVIEW以编程方式调整本身! - D

After struggling with this same problem for about a week, I was FINALLY able to get the camera preview to resize itself programmatically! :-D

preVIEW 是名我的 SurfaceView 在这code,我有建立这样它会调整自己是一半的宽度 RelativeLayout的,它的研究。

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.

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

现在您的使用,你需要看的preVIEW的分辨率,然后缩小的高度,或根据该决议相应宽度。

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.