开发者

Cropping/Clipping camera preview to just show top half of image

I'm developing an app that shows a camera pr开发者_高级运维eview on a SurfaceView but I only want to show the top half of the preview.

Is there a way of cropping/clipping the view or will I have to resort to obscuring the bottom half with something like an image,other view or drawing?

regards Simon


I am currently using this method to do the cropping (basically using the clip child ability of an absolute layout to clip a surfaceview child)

    <AbsoluteLayout android:clipChildren="true" android:layout_alignParentRight="true" android:layout_width="240dp" android:id="@+id/absoluteLayout1" android:layout_height="80dp">
    <SurfaceView android:id="@+id/swSurfaceView" android:layout_width="240dp" android:layout_height="160dp" android:visibility="visible"></SurfaceView>
</AbsoluteLayout>


Overlaying the SurfaceView with another view is the easiest way to do it... however, it's quite ugly if you ask me.

Why don't just set the SurfaceView height manually? Make it take the 50% of the screen space and it will do what you want. You don't provide code so we'll have to do some guesses: let's suppose you have a LinearLayout, then inside it you put two views: your surface view and another kind of view. Then, you set their height to be 0dip, and their weight to be 1... that should do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜