本文整理了Java中android.hardware.Camera.setPreviewCallback()
方法的一些代码示例,展示了Camera.setPreviewCallback()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Camera.setPreviewCallback()
方法的具体详情如下:
包路径:android.hardware.Camera
类名称:Camera
方法名:setPreviewCallback
暂无
代码示例来源:origin: daniulive/SmarterStreaming
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i(TAG, "surfaceDestroyed");
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testClearPreviewCallback() throws Exception {
TestPreviewCallback callback = new TestPreviewCallback();
assertThat(callback.camera).isNull();
assertThat(callback.data).isNull();
camera.setPreviewCallback(callback);
camera.setPreviewCallback(null);
shadowCamera.invokePreviewCallback("foobar".getBytes(UTF_8));
assertThat(callback.camera).isNull();
assertThat(callback.data).isNull();
camera.setOneShotPreviewCallback(callback);
camera.setOneShotPreviewCallback(null);
shadowCamera.invokePreviewCallback("foobar".getBytes(UTF_8));
assertThat(callback.camera).isNull();
assertThat(callback.data).isNull();
camera.setPreviewCallbackWithBuffer(callback);
camera.setPreviewCallbackWithBuffer(null);
shadowCamera.invokePreviewCallback("foobar".getBytes(UTF_8));
assertThat(callback.camera).isNull();
assertThat(callback.data).isNull();
}
代码示例来源:origin: TommyLemon/APIJSON
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
if (!useOneShotPreviewCallback) {
camera.setPreviewCallback(null);
}
if (previewHandler != null) {
Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x,
cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler for it");
}
}
代码示例来源:origin: yipianfengye/android-zxingLibrary
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
if (!useOneShotPreviewCallback) {
camera.setPreviewCallback(null);
}
if (previewHandler != null) {
Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x,
cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler for it");
}
}
代码示例来源:origin: TommyLemon/Android-ZBLibrary
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
if (!useOneShotPreviewCallback) {
camera.setPreviewCallback(null);
}
if (previewHandler != null) {
Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x,
cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler for it");
}
}
代码示例来源:origin: daniulive/SmarterStreaming
private void switchCamera() throws IOException {
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
if (currentCameraType == FRONT) {
mCamera = openCamera(BACK);
} else if (currentCameraType == BACK) {
mCamera = openCamera(FRONT);
}
initCamera(mSurfaceHolder);
}
代码示例来源:origin: TommyLemon/APIJSON
/**
* Tells the camera to stop drawing preview frames.
*/
public void stopPreview() {
if (camera != null && previewing) {
if (!useOneShotPreviewCallback) {
camera.setPreviewCallback(null);
}
camera.stopPreview();
previewCallback.setHandler(null, 0);
autoFocusCallback.setHandler(null, 0);
previewing = false;
}
}
代码示例来源:origin: daniulive/SmarterStreaming
private void switchCamera() throws IOException
{
pushCamera.setPreviewCallback(null);
pushCamera.stopPreview();
pushCamera.release();
if( pushCurrentCameraType == FRONT){
pushCamera = openCamera(BACK);
}else if(pushCurrentCameraType == BACK){
pushCamera = openCamera(FRONT);
}
initPushCamera(pushSurfaceHolder);
}
代码示例来源:origin: yipianfengye/android-zxingLibrary
/**
* Tells the camera to stop drawing preview frames.
*/
public void stopPreview() {
if (camera != null && previewing) {
if (!useOneShotPreviewCallback) {
camera.setPreviewCallback(null);
}
camera.stopPreview();
previewCallback.setHandler(null, 0);
autoFocusCallback.setHandler(null, 0);
previewing = false;
}
}
代码示例来源:origin: TommyLemon/Android-ZBLibrary
/**
* Tells the camera to stop drawing preview frames.
*/
public void stopPreview() {
if (camera != null && previewing) {
if (!useOneShotPreviewCallback) {
camera.setPreviewCallback(null);
}
camera.stopPreview();
previewCallback.setHandler(null, 0);
autoFocusCallback.setHandler(null, 0);
previewing = false;
}
}
代码示例来源:origin: cats-oss/android-gpuimage
@Override
public void run() {
int[] textures = new int[1];
GLES20.glGenTextures(1, textures, 0);
surfaceTexture = new SurfaceTexture(textures[0]);
try {
camera.setPreviewTexture(surfaceTexture);
camera.setPreviewCallback(GPUImageRenderer.this);
camera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}
});
代码示例来源:origin: LaiFeng-Android/SopCastComponent
public synchronized void stopPreview() {
if(mState != State.PREVIEW) {
return;
}
if(mCameraDevice == null) {
return;
}
mCameraDevice.setPreviewCallback(null);
Camera.Parameters cameraParameters = mCameraDevice.getParameters();
if (cameraParameters != null && cameraParameters.getFlashMode() != null
&& !cameraParameters.getFlashMode().equals(Camera.Parameters.FLASH_MODE_OFF)) {
cameraParameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
}
mCameraDevice.setParameters(cameraParameters);
mCameraDevice.stopPreview();
mState = State.OPENED;
}
代码示例来源:origin: TommyLemon/APIJSON
/**
* A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
* in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
* respectively.
*
* @param handler The handler to send the message to.
* @param message The what field of the message to be sent.
*/
public void requestPreviewFrame(Handler handler, int message) {
if (camera != null && previewing) {
previewCallback.setHandler(handler, message);
if (useOneShotPreviewCallback) {
camera.setOneShotPreviewCallback(previewCallback);
} else {
camera.setPreviewCallback(previewCallback);
}
}
}
代码示例来源:origin: yipianfengye/android-zxingLibrary
/**
* A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
* in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
* respectively.
*
* @param handler The handler to send the message to.
* @param message The what field of the message to be sent.
*/
public void requestPreviewFrame(Handler handler, int message) {
if (camera != null && previewing) {
previewCallback.setHandler(handler, message);
if (useOneShotPreviewCallback) {
camera.setOneShotPreviewCallback(previewCallback);
} else {
camera.setPreviewCallback(previewCallback);
}
}
}
代码示例来源:origin: TommyLemon/Android-ZBLibrary
/**
* A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
* in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
* respectively.
*
* @param handler The handler to send the message to.
* @param message The what field of the message to be sent.
*/
public void requestPreviewFrame(Handler handler, int message) {
if (camera != null && previewing) {
previewCallback.setHandler(handler, message);
if (useOneShotPreviewCallback) {
camera.setOneShotPreviewCallback(previewCallback);
} else {
camera.setPreviewCallback(previewCallback);
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetPreviewCallbacks() throws Exception {
TestPreviewCallback callback = new TestPreviewCallback();
assertThat(callback.camera).isNull();
assertThat(callback.data).isNull();
camera.setPreviewCallback(callback);
shadowCamera.invokePreviewCallback("foobar".getBytes(UTF_8));
assertThat(callback.camera).isSameAs(camera);
assertThat(callback.data).isEqualTo("foobar".getBytes(UTF_8));
}
代码示例来源:origin: yipianfengye/android-zxingLibrary
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
hasSurface = false;
if (camera != null) {
if (camera != null && CameraManager.get().isPreviewing()) {
if (!CameraManager.get().isUseOneShotPreviewCallback()) {
camera.setPreviewCallback(null);
}
camera.stopPreview();
CameraManager.get().getPreviewCallback().setHandler(null, 0);
CameraManager.get().getAutoFocusCallback().setHandler(null, 0);
CameraManager.get().setPreviewing(false);
}
}
}
代码示例来源:origin: doggycoder/AndroidOpenGLDemo
public void setOnPreviewFrameCallback(final IAiyaCamera.PreviewFrameCallback callback) {
if(mCamera!=null){
mCamera.setPreviewCallback(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
callback.onPreviewFrame(data,mPreSize.x,mPreSize.y);
}
});
}
}
代码示例来源:origin: doggycoder/AndroidOpenGLDemo
@Override
public void setOnPreviewFrameCallback(final PreviewFrameCallback callback) {
if(mCamera!=null){
mCamera.setPreviewCallback(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
callback.onPreviewFrame(data,mPreSize.x,mPreSize.y);
}
});
}
}
代码示例来源:origin: stackoverflow.com
public void surfaceChanged(SurfaceHolder holder,int format, int width,int height)
{
camera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
int width = parameters.getPreviewSize().width;
int height = parameters.getPreviewSize().height;
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
Rect rect = new Rect(0, 0, width, height);
YuvImage yuvimage=new YuvImage(data,ImageFormat.NV21,width,height,null);
yuvimage.compressToJpeg(rect, 100, outstr);
Bitmap bmp = BitmapFactory.decodeByteArray(outstr.toByteArray(), 0, outstr.size());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!