FocusSurfaceView拍照时只拍特定区域的照片

FocusSurfaceView

项目地址: CGmaybe10/FocusSurfaceView
简介:拍照时只拍特定区域的照片
更多: 作者    提 Bug   
标签:
SurfaceView局部拍照-

该库大部分参考 IsseiAoki 的 SimpleCropView https://github.com/IsseiAoki/SimpleCropView 
实现了在相机的预览界面指定一个区域的大小,形状和位置,只拍摄该指定区域里的图像 
支持 API Level 10 and above. 

   

使用方法:

在工程和 module 里的 build.gradle 分别添加

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
dependencies {
            compile 'com.github.CGmaybe10:FocusSurfaceView:v1.0.1'
    }
<com.cymaybe.foucsurfaceview.FocusSurfaceView
        android:id="@+id/preview_sv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:visibility="visible"
        app:focus_crop_height="267dp"
        app:focus_crop_width="200dp"
        app:focus_frame_can_change="true"
        app:focus_frame_color="@android:color/holo_green_dark"
        app:focus_frame_stroke_weight="1dp"
        app:focus_guide_color="@android:color/holo_green_dark"
        app:focus_guide_show_mode="not_show"
        app:focus_guide_stroke_weight="1dp"
        app:focus_handle_color="@android:color/holo_green_dark"
        app:focus_handle_show_mode="not_show"
        app:focus_handle_size="14dp"
        app:focus_min_frame_size="50dp"
        app:focus_mode="circle"
        app:focus_overlay_color="#66000000"
        app:focus_touch_padding="8dp"/>
private FocusSurfaceView previewSFV = (FocusSurfaceView) findViewById(R.id.preview_sv);
mCamera.autoFocus(new Camera.AutoFocusCallback() {
            @Override
            public void onAutoFocus(boolean success, Camera camera) {             
                    mCamera.takePicture(new Camera.ShutterCallback() {
                        @Override
                        public void onShutter() {
                        }
                    }, null, null, new Camera.PictureCallback() {
                        @Override
                        public void onPictureTaken(byte[] data, Camera camera) {
                            Bitmap cropBitmap = previewSFV.getPicture(data);                       
                        }
                    });
                }
            }
        });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值