简体   繁体   English

Android:在SurfaceView中缩放和转换相机预览流

[英]Android: Scale and translate camera preview stream in SurfaceView

I am using a SurfaceView to display the camera preview stream on the screen. 我正在使用SurfaceView在屏幕上显示相机预览流。 Now I want to use a online-computed rectangle region (say, the area from (0.2,0.3) to (0.5,0.6)) to fill the whole preview area, by stretching and shifting the preview stream (thus without changing the pictures taken later from the camera). 现在,我想使用在线计算的矩形区域(例如,从(0.2,0.3)到(0.5,0.6)的区域)通过拉伸和移动预览流来填充整个预览区域(因此无需更改所拍摄的图片)稍后从相机)。

On IOS, I achieved the same goal by applying my transform to the view. 在IOS上,我通过将变换应用于视图实现了相同的目标。 On Android, I suppose I should use SurfaceView.setScaleX/Y and SurfaceView.setTranslationX/Y to achieve the stretching and shifting, respectively. 在Android上,我想应该分别使用SurfaceView.setScaleX / Y和SurfaceView.setTranslationX / Y来实现拉伸和平移。 However, When I tried it out, it seems that either method leads to similar result: translating the preview. 但是,当我尝试时,似乎这两种方法都会导致类似的结果:翻译预览。 I even tried setRotation, which surprisingly move the preview around the point as a whole, instead of "rotating" it like you are tilting your head. 我什至尝试过setRotation,它令人惊讶地将预览作为一个整体移动,而不是像旋转头部一样“旋转”它。

Where did I get wrong? 我在哪里弄错了? Any suggestions on how could I achieve my goal? 关于如何实现目标的任何建议?

Though I still do not understand why scale and translate leads to similar result, I managed to get what I want by changing the left&right&top&bottom of the view (setLeft/Right/etc., effectively stretching and shifting the image). 尽管我仍然不明白为什么缩放和平移会导致类似的结果,但是我设法通过更改视图的左右,上下(setLeft / Right /等,有效地拉伸和移动图像)来获得所需的内容。 Not elegant, but works. 不优雅,但有效。

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

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