{"id":29079601,"url":"https://github.com/markusfisch/cameraview","last_synced_at":"2026-03-07T01:01:27.479Z","repository":{"id":139268060,"uuid":"101492222","full_name":"markusfisch/CameraView","owner":"markusfisch","description":"Camera view for Android","archived":false,"fork":false,"pushed_at":"2023-12-18T15:57:31.000Z","size":244,"stargazers_count":30,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-30T22:25:16.174Z","etag":null,"topics":["android-camera","android-library"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markusfisch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-26T14:49:55.000Z","updated_at":"2025-07-01T07:23:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"90793205-7e86-4158-a18d-6794ba8ec257","html_url":"https://github.com/markusfisch/CameraView","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/markusfisch/CameraView","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2FCameraView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2FCameraView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2FCameraView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2FCameraView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markusfisch","download_url":"https://codeload.github.com/markusfisch/CameraView/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2FCameraView/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30204446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-camera","android-library"],"created_at":"2025-06-27T17:06:37.976Z","updated_at":"2026-03-07T01:01:27.455Z","avatar_url":"https://github.com/markusfisch.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CameraView\n\nCamera view for Android. Supports orientation changes, fits preview image\ninto available view space and works with Gingerbread (minSDK 9) or better\n(since it still uses the deprecated Camera API). All in just ~500 lines of\ncode.\n\n## Why the deprecated Camera API?\n\nThis library is deliberately still on API level 9 (Android 2.3).\n\nIf you're not interested in supporting old versions of Android and/or\ndon't want to use the deprecated Camera API on newer devices, have a look at\nthe [CameraX support library](https://developer.android.com/training/camerax)\n(available from API level 21).\n\nThere, we finally find\n[PreviewView](https://developer.android.com/reference/androidx/camera/view/PreviewView)\nas part of the SDK. You can read\n[here](https://developer.android.com/training/camerax/preview)\nhow to implement it.\n\n## How to include\n\n### Gradle\n\nAdd the JitPack repository in your root build.gradle at the end of\nrepositories:\n\n```groovy\nallprojects {\n\trepositories {\n\t\t…\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n\nThen add the dependency in your app/build.gradle:\n\n```groovy\ndependencies {\n\timplementation 'com.github.markusfisch:CameraView:1.10.0'\n}\n```\n\n### Manually\n\nAlternatively you may just download the latest `aar` from\n[Releases](https://github.com/markusfisch/CameraView/releases) and put it\ninto `app/libs` in your app.\n\nThen make sure your `app/build.gradle` contains the following line in the\n`dependencies` block:\n\n```groovy\ndependencies {\n\timplementation fileTree(dir: 'libs', include: '*')\n\t…\n}\n```\n\n## How to use\n\nAdd it to a layout:\n\n```xml\n\u003cde.markusfisch.android.cameraview.widget.CameraView\n\txmlns:android=\"http://schemas.android.com/apk/res/android\"\n\tandroid:id=\"@+id/camera_view\"\n\tandroid:layout_width=\"match_parent\"\n\tandroid:layout_height=\"match_parent\"/\u003e\n```\n\nOr create it in Java:\n\n```java\nimport de.markusfisch.android.cameraview.widget.CameraView;\n\nCameraView cameraView = new CameraView(context);\n```\n\nIf your app supports *orientation changes*, please also enable the built-in\norientation listener:\n\n```java\ncameraView.setUseOrientationListener(true);\n```\n\nThis will take care of landscape to reverse landscape rotations (and vice\nversa). Without this, Android will re-use the Activity without calling a\nlife cycle method what will result in an upside down camera preview.\n\nRun `CameraView.openAsync()`/`.close()` in `onResume()`/`onPause()` of\nyour activity or fragment:\n\n```java\n@Override\npublic void onResume() {\n\tsuper.onResume();\n\tcameraView.openAsync(CameraView.findCameraId(\n\t\t\tCamera.CameraInfo.CAMERA_FACING_BACK));\n}\n\n@Override\npublic void onPause() {\n\tsuper.onPause();\n\tcameraView.close();\n}\n```\n\nTo set custom camera parameters or a preview listener to get the camera\nframe, set an OnCameraListener:\n\n```java\ncameraView.setOnCameraListener(new OnCameraListener {\n\t@Override\n\tpublic void onConfigureParameters(Camera.Parameters parameters) {\n\t\t// set additional camera parameters here\n\t}\n\n\t@Override\n\tpublic void onCameraError() {\n\t\t// handle camera errors\n\t}\n\n\t@Override\n\tpublic void onCameraReady(Camera camera) {\n\t\t// set a preview listener\n\t}\n\n\t@Override\n\tpublic void onPreviewStarted(Camera camera) {\n\t\t// start processing camera data\n\t}\n\n\t@Override\n\tpublic void onCameraStopping(Camera camera) {\n\t\t// clean up\n\t}\n});\n```\n\n## Preview resolution\n\nBy default CameraView picks the camera preview resolution that is closest\nto the size of the view on screen. If you want a lower or higher resolution,\nyou may use `CameraView.findBestPreviewSize()` (or a customized copy of it)\nin `OnCameraListener.onConfigureParameters()` to pick another size.\n\nFor example, if you want to pick the highest possible resolution, you can\ndo this:\n\n```java\ncameraView.setOnCameraListener(new OnCameraListener {\n\t@Override\n\tpublic void onConfigureParameters(Camera.Parameters parameters) {\n\t\tCamera.Size size = findBestPreviewSize(\n\t\t\t\tparameters.getSupportedPreviewSizes(),\n\t\t\t\tcameraView.getFrameWidth() * 1000,\n\t\t\t\tcameraView.getFrameHeight() * 1000);\n\t\tparameters.setPreviewSize(size.width, size.height);\n\t\t…\n\t}\n\t…\n```\n\n`CameraView.findBestPreviewSize()` returns the preview resolution that has\nthe smallest absolute distance to the given dimensions *and* is as close to\nthe aspect ratio of those dimensions as possible.\n\n## Preview layout\n\nOn some devices, the camera frame has a different aspect ratio than the\nscreen. The camera preview can either be laid so that it completely covers\nthe available `View` area (which is `SCALE_TYPE_CENTER_CROP`, the default),\nor so that it lies completely within it (`SCALE_TYPE_CENTER_INSIDE`).\n\nUse `CameraView.setScaleType()` with the appropriate constant:\n\n```java\ncameraView.setScaleType(CameraView.SCALE_TYPE_CENTER_INSIDE);\n```\n\n## Auto Focus\n\nTo enable Auto Focus, you should run `CameraView.setAutoFocus()` in\n`OnCameraListener.onConfigureParameters()`:\n\n```java\ncameraView.setOnCameraListener(new OnCameraListener {\n\t@Override\n\tpublic void onConfigureParameters(Camera.Parameters parameters) {\n\t\tCameraView.setAutoFocus(parameters);\n\t\t…\n\t}\n\t…\n```\n\n`CameraView.setAutoFocus()` picks the best available Auto Focus mode for\nmaking pictures. If you want something else, just have a look at this\nmethod and re-implement it in the client to fit your needs.\n\nNote that Auto Focus is not available on all devices. If your app depends\non Auto Focus, you should put a `\u003cuses-feature/\u003e` tag in your\n`AndroidManifest.xml` to make Google Play restrict your app to devices\nthat sport this feature:\n\n```xml\n\u003cuses-feature android:name=\"android.hardware.camera.autofocus\"/\u003e\n```\n\n## Tap to focus\n\nTo make the CameraView focus where a user taps, simply call `setTapToFocus()`\non your `cameraView` instance:\n\n```java\ncameraView.setTapToFocus();\n```\n\nThis adds a `View.OnTouchListener` to the `CameraView` to process the tap.\n\nIf you want to use a custom `View.OnTouchListener`, you can call `focusTo()`\nmanually in your touch listener instead of using `setTapToFocus()`:\n\n```java\nif (event.getActionMasked() == MotionEvent.ACTION_UP) {\n\tboolean success = focusTo(cameraView, event.getX(), event.getY());\n\t…\n}\n```\n\nIf `focusTo()` returns `false`, you should stop calling it because that\nmeans there was a `RuntimeException` that will be thrown (and catched) in\nthe future too.\n\n## Scene modes\n\nYou may use a predefined scene mode to use optimized camera parameters for\na specific purpose. Consequently, setting a scene mode may override previously\nset camera parameters, of course.\n\nFor example, to use `SCENE_MODE_BARCODE` (if it's available) do:\n\n```java\ncameraView.setOnCameraListener(new OnCameraListener {\n\t@Override\n\tpublic void onConfigureParameters(Camera.Parameters parameters) {\n\t\tList\u003cString\u003e modes = parameters.getSupportedSceneModes();\n\t\tif (modes != null) {\n\t\t\tfor (String mode : modes) {\n\t\t\t\tif (Camera.Parameters.SCENE_MODE_BARCODE.equals(mode)) {\n\t\t\t\t\tparameters.setSceneMode(mode);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t…\n\t}\n\t…\n```\n\nPlease note, not all devices support scene modes.\n\n## Demo\n\nYou can run the enclosed demo app to see if this widget is what you want.\nEither import it into Android Studio or, if you're not on that thing from\nRedmond, just type `make` to build, install and run.\n\nTap on the screen to switch between the front and back camera.\n\n## License\n\nThis widget is so basic, it should be Public Domain. And it is.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusfisch%2Fcameraview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkusfisch%2Fcameraview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusfisch%2Fcameraview/lists"}