百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

IDCardCamera

> 编程语言
开源

:fire:Android 自定义相机实现身份证拍照,并加入自动对焦和图片不规则裁剪。 https://www.jianshu.com/p/5e3cb0c63cd5

1.2K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

:fire:Android 自定义相机实现身份证拍照,并加入自动对焦和图片不规则裁剪。 https://www.jianshu.com/p/5e3cb0c63cd5

IDCardCamera

Android 自定义身份证相机

README of English

效果图

APK

点击下载APK

功能特点

  • 自定义相机界面
  • 支持开启闪光灯
  • 支持手动触摸屏幕对焦
  • 支持自动对焦
  • 支持图片自动裁剪
  • 支持图片手动不规则裁剪

使用

Step 1. 添加 JitPack 仓库

在项目的 build.gradle 添加 JitPack 仓库

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Step 2. 添加依赖

在需要使用的 module 中添加依赖

dependencies {
	compile 'com.github.wildma:IDCardCamera:1.1.1'
}

Step 3. 打开拍照界面

  • 身份证正面
IDCardCamera.create(this).openCamera(IDCardCamera.TYPE_IDCARD_FRONT);
  • 身份证反面
IDCardCamera.create(this).openCamera(IDCardCamera.TYPE_IDCARD_BACK);

注意: create() 方法的参数传的是上下文,在 Activity 中传 activity.this,在 Fragment 中传 fragment.this

Step 4. 在 onActivityResult 方法中获取裁剪后的图片

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	if (resultCode == IDCardCamera.RESULT_CODE) {
		//获取图片路径,显示图片
		final String path = IDCardCamera.getImagePath(data);
		if (!TextUtils.isEmpty(path)) {
			if (requestCode == IDCardCamera.TYPE_IDCARD_FRONT) { //身份证正面
				mIvFront.setImageBitmap(BitmapFactory.decodeFile(path));
			} else if (requestCode == IDCardCamera.TYPE_IDCARD_BACK) {  //身份证反面
				mIvBack.setImageBitmap(BitmapFactory.decodeFile(path));
			}
		}
	}
}

清理缓存

实际开发中将图片上传到服务器成功后需要删除全部缓存图片,调用如下方法即可:

FileUtils.clearCache(this);

详细介绍请看文章:Android 自定义相机实现身份证拍照,并加入自动对焦与图片不规则裁剪

ps:如果对你有帮助,点下 star 就是对我最大的认可。

感谢

  • CertificateCamera
  • PhotoPolygonCropper
  • SweetCamera

License

   Copyright 2018 wildma

   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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaautofocus-cameracustom-cameraid-card-camerairregular-cutting-of-pictures

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言