Android自定义证件拍照控件之CameraCardCrop

Github传送门

CameraCardCropDemo

一个卡片(证件)拍照裁剪框架。

Gradle

compile 'me.zhouzhuo810.cameracardcrop:camera-card-crop:1.0.2'

Features

  • Support Android 6.0 permissions.

What does it look like ?

cameracrop2.png
cameracrop1.png

Notice

card

---------------------
|       width       |
|                   |
|                   |height
|                   |
---------------------
phone
------------------------------------
|                                   |
|                                   |
|                                   |
|                                   |
|                                   |
|      mask                         |
|                                   |
|                width              |
|    ------------------------       |
|    |                       |      |
|    |                height |      | screen height
|    |         rect          |      |
|    |                       |      |
|    ------------------------       |
|                                   |
|                                   |
|                                   |
|                                   |
|                                   |
|            screen width           |
-------------------------------------
CameraConfig.RATIO_WIDTH = card's width
CameraConfig.RATIO_HEIGHT = card's height
CameraConfig.PERCENT_WIDTH = rect'swidth / screen's width

Usage

step 1. Add Activity in your AndroidManifest.xml file.

    <activity android:name="me.zhouzhuo810.cameracardcrop.CropActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.NoActionBar">
    </activity>

step 2. Add permissions in your AndroidManifest.xml file.

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

step 3. Example for use.

    public void takePhoto(View v) {
        Intent intent = new Intent(MainActivity.this, CropActivity.class);
        intent.putExtra(CameraConfig.RATIO_WIDTH, 855);
        intent.putExtra(CameraConfig.RATIO_HEIGHT, 541);
        intent.putExtra(CameraConfig.PERCENT_WIDTH, 0.8f);
        intent.putExtra(CameraConfig.MASK_COLOR, 0x2f000000);
        intent.putExtra(CameraConfig.RECT_CORNER_COLOR, 0xff00ff00);
        intent.putExtra(CameraConfig.TEXT_COLOR, 0xffffffff);
        intent.putExtra(CameraConfig.HINT_TEXT, "请将方框对准证件拍照");
        intent.putExtra(CameraConfig.IMAGE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath()+"/CameraCardCrop/"+System.currentTimeMillis()+".jpg");
        startActivityForResult(intent, 0x01);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 0x01) {
                String path = data.getStringExtra(CameraConfig.IMAGE_PATH);
                ivPic.setImageURI(Uri.parse("file://"+path));
            }
        }
    }

Log

  • 1.0.2 Fix flashlight not support bugs.
  • 1.0.1 Revise layout size.

License

Copyright © zhouzhuo810

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 14,594评论 5 6
  • 清楚地记得四年前初见卓爷,我进221宿舍,一个肥硕的大个子和几个同学围坐在桌子前打牌,旁边有一个恬静的阿姨在收拾床...
    王光翟阅读 3,456评论 0 0
  • 如果可以,我希望没做那个决定,那样就可以对你伤害少一点。 一个人普通的爱情故事,开始于一个女她对男他的单恋。本来她...
    Zev_zhongwei阅读 1,501评论 0 0
  • 岁月悠悠恍惚过了多少年青葱岁月的痕迹似在昨天 那一日黄昏从你家门前经过一丛丛的菊花开的正欢我为它们驻足止步不前被那...
    玉生烟阅读 1,865评论 0 1
  • 都说没有对比就没有伤害,没有惩罚,奖励形同虚设。没有难过没人觉得快乐的宝贵,没有可恶善良也显得不足珍贵。 ...
    快乐红宝宝阅读 2,206评论 0 0