gitmyhub

TakePhoto

Java ★ 7.2k updated 6y ago

一款用于在Android设备上获取照片(拍照或从相册、文件中选择)、裁剪图片、压缩图片的开源工具库

TakePhoto is an Android library that lets your app grab photos from the camera, gallery, or file system with one Gradle dependency, including built-in cropping, compression, and permission handling.

JavaAndroidGradleMavensetup: easycomplexity 2/5

TakePhoto is an Android library written in Java that handles the common task of getting a photo into an app. It covers three entry points: taking a photo with the camera, picking one from the device gallery, or selecting one from the file system. All three sources can feed into the same result handling code, which reduces the amount of work a developer needs to write separately for each case.

Beyond simply obtaining an image, the library also handles cropping and compression. Both operations work on single images or in batch mode when a user selects multiple photos at once. The crop step uses a built-in cropping tool, and the compression step supports multiple compression strategies. Parameters for both operations can be configured per use.

One area the library addresses that is often tedious is Android permissions. Requesting access to the camera and storage requires specific runtime permission flows, especially on Android 6 and later. TakePhoto manages these requests automatically so developers do not need to write separate permission-handling code. It also handles the case where Android reclaims the camera activity from memory mid-session, restoring state so the user does not lose their progress.

If a particular method of selecting an image is not supported by the Android version or device manufacturer variant the user is running, the library automatically falls back to an alternative method rather than failing. This improves compatibility across the wide variety of Android devices in use.

The UI for the built-in album picker and cropping tool can be customized through standard Android layout and resource files, so the look can be adjusted to match an app's visual style. The library is added to an Android project via a single Gradle or Maven dependency and is licensed under Apache 2.0. The README and code documentation are written in Chinese.

Where it fits