# titan-camera **Repository Path**: openneusoft/titan-camera ## Basic Information - **Project Name**: titan-camera - **Description**: 实现一个应用内置相机,可以处理预览大小,预览拉伸 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2021-04-29 - **Last Updated**: 2024-07-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Titan Camera TitanCamera is Camera library for harmonyos platform. It is build upon Camera API, and handles the selection of Camera API automatically based on SDK version. It solves most of the common issues faced by developer while developing in-app camera, such as Stretching of image etc. ## Getting Started This project contains **titan-camera** library and a tester app. To use the app you need to download the zip file or clone the repository and run the project in DevEco Studio. You will find MainActivity.java class in tester app where the demo code is written to help you to understand how to use **titan-camera** for your project. ## Project introduction ``` Project name:titan-camera Series:Third party component adaptation and transplantation of ohos function:titan-camera is a mobile phone built-in camera, which supports the basic functions of the camera status:complete Original project version:v1.0, sha1:185c2eb2568ac8fdabae2473116a2569506cf878 programing language:Java ``` ### Test display ![](test.gif) ### Features * Easily integrateable in-app camera * Fast and reliable * Handles preview sizing, preview stretching, FPS rate, bitmap handing, out-of-memory errors, etc. * Automatic selection of camera API to use * Automatic handles if device does not have any or front camera. * Take high-quality images * Well tested * Light weight ### Installation 1. Installation tutorial ``` 1,Compile the har package titan-camera.har. 2,Start deveco studio and import the compiled har package into the project directory "entry > LIBS". 3,Add dependency in build.gradle file under moudle level, and add reference to har package in LIBS directory in dependencies tag. ``` 2. Another way ``` 1) In all projects of build. Gradle, add the Maven warehouse address where har is located. allprojects { repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } jcenter() } } 2)In the dependencies closure of build.gradle in the application module, add the following code: dependencies { implementation "io.github.dzsf:TITAN_CAMERA:1.0.1" } ``` ### How do I use Camera Create Camera object through CameraRequestBuilder to start camera. You can start camera from Activity instance, Fragment instance, or context instance. ``` new CameraRequestBuilder() .setEnableSwitchCamera(false) //enable switch button to switch between front and back camera .setLensFacing(CameraProperties.LENS_FACING_BACK) //Camera to start (Front or back) .setCustomLayoutId(null) //Any layout that goes on top of the preview .build() // returns camera object .startCamera(context, this::onCapture) // starts camera ``` **Note 1: setEnableSwitchCamera() It is the flag to set whether to support the front / rear camera. The default is to support the front camera. If you want to support the switching between the front camera and the rear camera, you can make the following modifications** ``` new CameraRequestBuilder() .setEnableSwitchCamera(true) //enable switch button to switch between front and back camera ... ``` **Note 2: You can have the result image file in *CaptureResult (Callback)* or *onActivityResult*. You can receive result in Activity's *onActivityResult* as well as Fragment's *OnActivityResult*. You should consider getting results in *onActivityResult* if you want to do a FragmentTransaction after receving File.** ### CameraRequestBuilder | Method | Descritpion | | ------------- | ------------- | | setLensFacing | Sets the camera to be used. Example, CameraProperties.LENS_FACING_BACK | | setEnableSwitchCamera | Used to allow user to switch between front and back camera | | setCustomLayoutId | Used to plalce and placeholder layout on the top of camera preview | | setRootPath | Sets the root path where captured image will be saved. Default Picture directory of external storage | | setImageFileName | Sets the name of the campture file | | build | returns the Camera object used to start Camera | ### Camera | Method | Descritpion | | ----------- | ------------- | | startCamera | Takes context and CaptureResutlt callback where you will receive captured image | ### Version **1.0.1** ### Libraries used * [PhotoView](https://gitee.com/openharmony-tpc/PhotoView) - To display the captured image with sliding feature. ### Author **Vinod Kumar**