简体   繁体   中英

Android: Scale and translate camera preview stream in SurfaceView

I am using a SurfaceView to display the camera preview stream on the screen. 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).

On IOS, I achieved the same goal by applying my transform to the view. On Android, I suppose I should use SurfaceView.setScaleX/Y and SurfaceView.setTranslationX/Y to achieve the stretching and shifting, respectively. 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.

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). Not elegant, but works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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