CameraCardCrop
一个卡片(证件)拍照裁剪框架。
(A cutting framework for card-photo.)
Gradle
1
| compile 'me.zhouzhuo810.cameracardcrop:camera-card-crop:1.0.2'
|
Screenshot
Notice
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| 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.
1 2 3 4
| <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.
1 2 3 4 5 6
| <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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| 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)); } } }
|