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

RxCamera

> 编程语言
开源

适用于 Android 相机的 RxJava 样式 API

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

工具介绍

适用于 Android 相机的 RxJava 样式 API

RxCamera

RxJava style camera API for android, it based on android.hardware.camera


Add to your project dependence:

groovy
repositories {
        jcenter()
}
dependencies {
	compile 'com.ragnarok.rxcamera:lib:0.0.5'
}

Basic Usage:

  1. set the camera parameter by choose a RxCameraConfig, which created by RxCameraConfig.Builder:

    java
    RxCameraConfig config = new RxCameraConfig.Builder()
                .useBackCamera()
                .setAutoFocus(true)
                .setPreferPreviewFrameRate(15, 30)
                .setPreferPreviewSize(new Point(640, 480), false)
                .setHandleSurfaceEvent(true)
                .build();

    for all camera config currently support, please see RxCameraConfig

  2. open camera

    java
    RxCamera.open(context, config)

    it return an RxJava Observable object, the type is Observable

  3. bind a SurfaceView or TextureView and startPreview

    since RxCamera.open is return an Observable, so you can chain the call like this

    java
    RxCamera.open(this, config).flatMap(new Func1>() {
          @Override
          public Observable call(RxCamera rxCamera) {
              return rxCamera.bindTexture(textureView);
              // or bind a SurfaceView:
              // rxCamera.bindSurface(SurfaceView)
          }
    }).flatMap(new Func1>() {
          @Override
          public Observable call(RxCamera rxCamera) {
              return rxCamera.startPreview();
          }
    });

    both RxCamera.bindTexture and RxCamera.startPreview will return an Observable object

    PS: if set isHandleSurfaceEventto true(set by setHandleSurfaceEvent(true) in RxCameraConfigChooser), RxCamera will do the actual camera start preview action when the surface is available, otherwise it will start preview immediately, and may failed if surface is not available, in this case, the return Observable will call onError

  4. switch camera

    switch the camera in runtime

    java
     camera.switchCamera();    

    and it will also change the internal camera config, so after switch camera, the camera.getConfig will return with new setting


request camera data

RxCamera support many styles of camera data requests:

  • successiveDataRequest

    java
    camera.request().successiveDataRequest()

    it will return the camera data infinitely

  • periodicDataRequest

    java
    camera.request().periodicDataRequest(1000)

    as the name, it will return camera data periodic, pass the interval in millisecond

  • oneShotRequest

    java
    camera.request().oneShotRequest()

    it will return the camera data only once

  • takePictureRequest

    java
    camera.request().takePictureRequest(boolean isContinuePreview, Func shutterAction, boolean openFlash)

    the encapsulation of takePicture API, if isContinuePreview set to true, the RxCamera will try to restart preview after capture the picture, otherwise will behave as system takePicture call, stop preview after captured successfully

    and the shutterAction will called after picture just captured, like the [ShutterCallback] (http://developer.android.com/intl/es/reference/android/hardware/Camera.ShutterCallback.html) (actually it is called in the system shutterCallback)

    and the openFlash if set to true, it will open the flash when taking picture, and automatically close it after this request

  • FaceDetectionRequest

    java
    camera.request().faceDetectionRequest()

    the encapsulation of Camera.FaceDetectionListener, it will return the faces location in CameraData.faceList


All the data request will return an Observalbe

the RxCameraData contained these 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 YUV420SP
    • Matrix rotateMatrix, this matrix help you rotate the camera data in portrait
    • Camera.Face[] faceList, the locatoin of faces, only returned in FaceDetectionRequest

camera action request

the camera action request will change the behavior of the camera

  • zoom and somoothZoom action:

    java
    camera.action().zoom(int level)
    camera.action().smoothZoom(int level)

    change the camera zoom level

  • open or close the flash

    java
    camera.action().flashAction(boolean isOn)
  • area focus and area metering

    java
    camera.action().areaFocusAction(List focusAreaList)
    camera.action().areaMeterAction(List focusAreaList)

    and there is a helper function to convert the coordinate to [-1000, 1000], which is suitable for Camera.Area, in CameraUtil:

    java
    Rect transferCameraAreaFromOuterSize(Point center, Point outerSize, int size)

    check out the example to see how to use this

This project still in very early stage, and welcome the pull request

Issues· 0 开放

查看全部 Issues在 GitHub 打开

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

> 标签

Java

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

> 工具信息

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

> 相关工具

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