本文整理了Java中android.hardware.Camera.startPreview()
方法的一些代码示例,展示了Camera.startPreview()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Camera.startPreview()
方法的具体详情如下:
包路径:android.hardware.Camera
类名称:Camera
方法名:startPreview
暂无
代码示例来源:origin: stackoverflow.com
Camera cam = Camera.open();
Parameters p = cam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
代码示例来源:origin: stackoverflow.com
SurfaceView preview = (SurfaceView) findViewById(R.id.PREVIEW);
SurfaceHolder mHolder = preview.getHolder();
mHolder.addCallback(this);
Camera mCamera = Camera.open();
mCamera.setPreviewDisplay(mHolder);
// Turn on LED
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);
mCamera.startPreview();
...
// Turn off LED
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
mCamera.setParameters(params);
mCamera.stopPreview();
mCamera.release();
代码示例来源:origin: stackoverflow.com
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
} catch (IOException e) {
mCamera.stopPreview();
mCamera.release();
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
} catch (Exception e) {
代码示例来源:origin: googlesamples/android-vision
/**
* Opens the camera and starts sending preview frames to the underlying detector. The supplied
* surface holder is used for the preview so frames can be displayed to the user.
*
* @param surfaceHolder the surface holder to use for the preview frames
* @throws IOException if the supplied surface holder could not be used as the preview display
*/
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start(SurfaceHolder surfaceHolder) throws IOException {
synchronized (mCameraLock) {
if (mCamera != null) {
return this;
}
mCamera = createCamera();
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
mProcessingThread = new Thread(mFrameProcessor);
mFrameProcessor.setActive(true);
mProcessingThread.start();
}
return this;
}
代码示例来源:origin: vondear/RxTool
@SuppressLint("NewApi")
void setUpPreview() {
try {
if (mPreview.getOutputClass() == SurfaceHolder.class) {
final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
if (needsToStopPreview) {
mCamera.stopPreview();
}
mCamera.setPreviewDisplay(mPreview.getSurfaceHolder());
if (needsToStopPreview) {
mCamera.startPreview();
}
} else {
mCamera.setPreviewTexture((SurfaceTexture) mPreview.getSurfaceTexture());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: vondear/RxTool
@Override
void setDisplayOrientation(int displayOrientation) {
if (mDisplayOrientation == displayOrientation) {
return;
}
mDisplayOrientation = displayOrientation;
if (isCameraOpened()) {
mCameraParameters.setRotation(calcCameraRotation(displayOrientation));
mCamera.setParameters(mCameraParameters);
final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
if (needsToStopPreview) {
mCamera.stopPreview();
}
mCamera.setDisplayOrientation(calcDisplayOrientation(displayOrientation));
if (needsToStopPreview) {
mCamera.startPreview();
}
}
}
代码示例来源:origin: stackoverflow.com
myCamera.release(); // release the camera for other applications
myCamera = null;
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
} catch (IOException e) {
代码示例来源:origin: stackoverflow.com
camera.release();
camera = null;
camera.startPreview();
previewIsRunning = true;
camera.stopPreview();
previewIsRunning = false;
代码示例来源:origin: robolectric/robolectric
@Test
public void testStopPreview() throws Exception {
camera.startPreview();
assertThat(shadowCamera.isPreviewing()).isTrue();
camera.stopPreview();
assertThat(shadowCamera.isPreviewing()).isFalse();
}
代码示例来源:origin: stackoverflow.com
Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
setLayoutParams(new FrameLayout.LayoutParams(
previewSize.width, previewSize.height, Gravity.CENTER));
} catch (IOException t) {}
mCamera.startPreview();
this.setVisibility(INVISIBLE); // Make the surface invisible as soon as it is created
代码示例来源:origin: chengzichen/KrGallery
@SuppressLint("NewApi")
@Override
public void run() {
Camera camera = session.cameraInfo.camera;
try {
if (camera == null) {
camera = session.cameraInfo.camera = Camera.open(session.cameraInfo.cameraId);
}
camera.startPreview();
} catch (Exception e) {
session.cameraInfo.camera = null;
if (camera != null) {
camera.release();
}
e.printStackTrace();
}
}
});
代码示例来源:origin: stackoverflow.com
Camera cam;
void ledon() {
cam = Camera.open();
Parameters params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_ON);
cam.setParameters(params);
cam.startPreview();
cam.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});
}
void ledoff() {
cam.stopPreview();
cam.release();
}
代码示例来源:origin: vondear/RxTool
/**
* 打开闪光灯
*
* @return
*/
public static void openFlashLight() {
try {
if (camera == null) {
camera = Camera.open();
camera.startPreview();
}
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
mCamera.stopPreview();
mCamera.release();
mCamera = null;
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
mCamera.startPreview();
代码示例来源:origin: googlesamples/android-vision
/**
* Opens the camera and starts sending preview frames to the underlying detector. The supplied
* surface holder is used for the preview so frames can be displayed to the user.
*
* @param surfaceHolder the surface holder to use for the preview frames
* @throws IOException if the supplied surface holder could not be used as the preview display
*/
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start(SurfaceHolder surfaceHolder) throws IOException {
synchronized (cameraLock) {
if (camera != null) {
return this;
}
camera = createCamera();
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
processingThread = new Thread(frameProcessor);
frameProcessor.setActive(true);
processingThread.start();
}
return this;
}
代码示例来源:origin: google/cameraview
@SuppressLint("NewApi")
void setUpPreview() {
try {
if (mPreview.getOutputClass() == SurfaceHolder.class) {
final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
if (needsToStopPreview) {
mCamera.stopPreview();
}
mCamera.setPreviewDisplay(mPreview.getSurfaceHolder());
if (needsToStopPreview) {
mCamera.startPreview();
}
} else {
mCamera.setPreviewTexture((SurfaceTexture) mPreview.getSurfaceTexture());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: google/cameraview
@Override
void setDisplayOrientation(int displayOrientation) {
if (mDisplayOrientation == displayOrientation) {
return;
}
mDisplayOrientation = displayOrientation;
if (isCameraOpened()) {
mCameraParameters.setRotation(calcCameraRotation(displayOrientation));
mCamera.setParameters(mCameraParameters);
final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
if (needsToStopPreview) {
mCamera.stopPreview();
}
mCamera.setDisplayOrientation(calcDisplayOrientation(displayOrientation));
if (needsToStopPreview) {
mCamera.startPreview();
}
}
}
代码示例来源:origin: stackoverflow.com
Camera camera;
if (Camera.getNumberOfCameras() >= 2) {
//if you want to open front facing camera use this line
camera = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
//if you want to use the back facing camera
camera = Camera.open(CameraInfo.CAMERA_FACING_BACK);
}
try {
camera.setPreviewDisplay("your surface holder here");
camera.startPreview();
} catch (Exception e) {
camera.release();
}
代码示例来源:origin: pedroSG94/rtmp-rtsp-stream-client-java
public void setPreviewOrientation(final int orientation) {
this.rotation = orientation;
if (camera != null && running) {
camera.stopPreview();
camera.setDisplayOrientation(orientation);
camera.startPreview();
}
}
代码示例来源:origin: stackoverflow.com
mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
for(Camera.Size str: mSupportedPreviewSizes)
Log.e(TAG, str.width + "/" + str.height);
mCamera.stopPreview();
} catch (Exception e){
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
mCamera.setParameters(parameters);
mCamera.setDisplayOrientation(90);
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
内容来源于网络,如有侵权,请联系作者删除!