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, "請將方框?qū)首C件拍照");
        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.
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,640評論 5 6
  • 清楚地記得四年前初見卓爺,我進221宿舍,一個肥碩的大個子和幾個同學圍坐在桌子前打牌,旁邊有一個恬靜的阿姨在收拾床...
    王光翟閱讀 559評論 0 0
  • 如果可以,我希望沒做那個決定,那樣就可以對你傷害少一點。 一個人普通的愛情故事,開始于一個女她對男他的單戀。本來她...
    Zev_zhongwei閱讀 256評論 0 0
  • 歲月悠悠恍惚過了多少年青蔥歲月的痕跡似在昨天 那一日黃昏從你家門前經(jīng)過一叢叢的菊花開的正歡我為它們駐足止步不前被那...
    玉生煙閱讀 307評論 0 1
  • 都說沒有對比就沒有傷害,沒有懲罰,獎勵形同虛設。沒有難過沒人覺得快樂的寶貴,沒有可惡善良也顯得不足珍貴。 ...
    快樂紅寶寶閱讀 321評論 0 0

友情鏈接更多精彩內(nèi)容