Android获取Linux图像信息,Android相机是如何获取到图像的

在研究zxing的过程中,脑袋中一直有个疑惑,那个相机并没有拍照,它是怎么获取图像的

带着这个疑惑查看Camera源码

Camera源码中有这样一个接口:

public interface PreviewCallback

{

/**

* Called as preview frames are displayed.  This callback is invoked

* on the event thread {@link #open(int)} was called from.

*

*

If using the {@link Android.graphics.ImageFormat#YV12} format,

* refer to the equations in {@link Camera.Parameters#setPreviewFormat}

* for the arrangement of the pixel data in the preview callback

* buffers.

*

* @param data the contents of the preview frame in the format defined

*  by {@link android.graphics.ImageFormat}, which can be queried

*  with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.

*  If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}

*            is never called, the default will be the YCbCr_420_SP

*            (NV21) format.

* @param camera the Camera service object.

*/

void onPreviewFrame(byte[] data, Camera camera);

};

Called as preview frames are displayed. This callback is invoked on the event thread open(int) was called from.

其中这个  “open(int) ”很关键

android.hardware.Camera.PreviewCallback

Callback interface used to deliver copies of preview frames as they are displayed.

See Also:

setPreviewCallback(Camera.PreviewCallback)

setOneShotPreviewCallback(Camera.PreviewCallback)

setPreviewCallbackWithBuffer(Camera.PreviewCallback)

startPreview()

选这其中一个打开:

/**

*

Installs a callback to be invoked for the next preview frame in

* addition to displaying it on the screen.  After one invocation, the

* callback is cleared. This method can be called any time, even when

* preview is live.  Any other preview callbacks are overridden.

*

*

If you are using the preview data to create video or still images,

* strongly consider using {@link android.media.MediaActionSound} to

* properly indicate image capture or recording start/stop to the user.

*

* @param cb a callback object that receives a copy of the next preview frame,

*    or null to stop receiving callbacks.

* @see android.media.MediaActionSound

*/

public final void setOneShotPreviewCallback(PreviewCallback cb) {

mPreviewCallback = cb;

mOneShot = true;

mWithBuffer = false;

if (cb != null) {

mUsingPreviewAllocation = false;

}

setHasPreviewCallback(cb != null, false);

}

单触发模式,只要预览ok,就会启动回调函数

onPreviewFrame(byte[] data, Camera camera)

把当前的视窗类的Frame的信息装到byte[] data ,这样程序就得到预览窗口的图像数据。

其他的两个是连续触发模式,接近视频流的模式,每一帧都会返给数组,摄像机程序的实现底层肯定调用这个函数。

0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值