Android RxJava(ReactiveX Java), RxAndroid(ReactiveX Java Android) style API for Android Camera with Android (Runtime over 6.0) RxPermissions
Current version: [0.1.0]
Gradle:
repositories {
jcenter()
}
dependencies {
compile 'com.github.dubulee:reactivexcamera:0.1.0'
}
-
set the camera parameter by choose a [ReactiveXCameraConfig]which created by [ReactiveXCameraConfigChooser]
ReactiveXCameraConfig config = ReactiveXCameraConfigChooser.obtain(). useBackCamera(). setAutoFocus(true). setPreferPreviewFrameRate(30, 30). setPreferPreviewSize(new Point(640, 480)). setHandleSurfaceEvent(true). get();
for all camera currently support, please see [ReactiveXCameraConfig]
-
open camera
ReactiveXCamera.open(context, config)
it return an ReactiveXJava Observable object, the type is
Observable<ReactiveXCamera> -
bind a
SurfaceVieworTextureViewand startPreviewsince
ReactiveXCamera.openis return an Observable, so you can chain the call like thisReactiveXCamera.open(this, config).flatMap(new Func1<ReactiveXCamera, Observable<ReactiveXCamera>>() { @Override public Observable<ReactiveXCamera> call(ReactiveXCamera rxCamera) { return rxCamera.bindTexture(textureView); // or bind a SurfaceView } }).flatMap(new Func1<ReactiveXCamera, Observable<ReactiveXCamera>>() { @Override public Observable<ReactiveXCamera> call(ReactiveXCamera rxCamera) { return rxCamera.startPreview(); } });
both
ReactiveXCamera.bindTextureandReactiveXCamera.startPreviewwill return anObservable<ReactiveXCamera>object -
request camera data
ReactiveXCamera support many styles of camera data requests:
-
successiveDataRequest
camera.request().successiveDataRequest()
it will return the camera data infinitely
-
periodicDataRequest
camera.request().periodicDataRequest(1000)
as the name, it will return camera data periodic, pass the interval in millisecond
-
oneShotRequest
camera.request().oneShotRequest()
it will return the camera data only once
-
takePictureRequest
camera.request().takePictureRequest(boolean isContinuePreview, Func shutterAction)
all the data request will return an
Observalbe<ReactiveXCameraData>the
ReactiveXCameraDatacontained two fields:byte[] cameraData, the raw data of camera, for the takePicture request, it will return the jpeg encode byte, other request just return raw camera preview data, if you don't set preview format, the default is YUV420SPMatrix rotateMatrix, this matrix help you rotate the camera data in portrait
-
Copyright 2015 DUBULEE
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.