简体   繁体   English

Android Surfaceview相机拉伸

[英]Android surfaceview camera stretched

I have an activity with action bar, SurfaceView (fullScreen, Behind the action bar) and a capture button at the bottom of the screen but on the surfaceView. 我有一个带有动作栏,SurfaceView(全屏,位于动作栏后面)的活动,并且在屏幕底部但在SurfaceView上有一个捕获按钮。 in the SurfaceViewChange I'm scanning all the supported Picture Sizes and chosing the Highest, but when I'm putting the same values in the Preview the outcome is stretched and if I take a picture it look ok, If I'm using the device screen height and width for the preview than its not stretched but at the result picture there are thing that were off frame. 在SurfaceViewChange中,我正在扫描所有受支持的图片大小并选择“最高”,但是当我在“预览”中放置相同的值时,结果将被拉伸,如果我拍摄图片看起来还可以,如果我正在使用设备预览的屏幕高度和宽度比未拉伸的要高,但是在结果图片中有些东西不在画框内。 All I want is an activity that takes picture with the highest resolution supported and preview it fine and play around with the captured picture. 我想要的是一项活动,该活动以支持的最高分辨率拍摄照片并进行精细预览,然后播放捕获的照片。

The activity is in portrait! 活动是肖像!

any ideas? 有任何想法吗?

The aspect ratio of the SurfaceView needs to match the aspect ratio of the camera preview. SurfaceView的纵横比需要与相机预览的纵横比匹配。 You can do this with a custom FrameLayout class. 您可以使用自定义FrameLayout类来执行此操作。

For an example, see AspectFrameLayout in Grafika. 有关示例,请参见Grafika中的AspectFrameLayout。 You can see it used in the "Show + capture camera" and "Continuous capture" activities. 您可以在“显示+捕获相机”和“连续捕获”活动中看到它。 Note how it's used in the layouts . 注意如何在布局中使用它。 Once you have it set up, you make one call with the camera preview parameters to set the desired aspect ratio, and the layout adjusts to match. 设置完成后,您可以使用相机预览参数拨打电话以设置所需的宽高比,然后布局会进行调整以匹配。

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

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