And*_*son 14 android android-camera
我没有找到任何方法来裁剪相机ppreview,然后在SurfaceView上显示它.
Android - 可以裁剪相机预览吗?
mom*_*omo 16
您可以在没有叠加视图的情况下执行此操作(这在所有情况下都不起作用).
子类ViewGroup,将SurfaceView添加为唯一的子项,然后:
基本上,
public class CroppedCameraPreview extends ViewGroup {
private SurfaceView cameraPreview;
public CroppedCameraPreview( Context context ) {
super( context );
// i'd probably create and add the SurfaceView here, but it doesn't matter
}
@Override
protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec ) {
setMeasuredDimension( croppedWidth, croppedHeight );
}
@Override
protected void onLayout( boolean changed, int l, int t, int r, int b ) {
if ( cameraPreview != null ) {
cameraPreview.layout( 0, 0, actualPreviewWidth, actualPreviewHeight );
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以将相机预览(SurfaceView)放在ScrollView内的LinearLayout中.当摄像机输出大于您设置的LinearLayout时,您可以通过编程方式滚动它并禁用用户滚动.这样您就可以轻松地模拟相机裁剪:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="640dip"
android:layout_height="282dip"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:id="@+id/linearLayoutBeautyContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/surfaceViewBeautyCamera"/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20807 次 |
| 最近记录: |