Android: Camera2 传递给相机服务的参数错误
Android: Camera2 Bad argument passed to camera service
谁能告诉我我做错了什么...我想使用 SurfaceView 捕捉我有预览屏幕的图像。我能够在表面视图上显示预览。
这是我捕获图像的代码
if (mCameraSession == null && mCameraDevice == null) return;
ImageReader reader = ImageReader.newInstance(mTexturePreviewSize.getWidth(),
mTexturePreviewSize.getHeight(),
ImageFormat.JPEG, 1);
reader.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler);
Surface surface = reader.getSurface();
try {
CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
requestBuilder.addTarget(surface);
mCameraSession.capture(requestBuilder.build(), sessionCaptureListener, null);
下面是我收到的错误信息。
java.lang.IllegalArgumentException: Bad argument passed to camera service
at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.java:114)
at android.hardware.camera2.utils.CameraBinderDecorator$CameraBinderDecoratorListener.onAfterInvocation(CameraBinderDecorator.java:73)
at android.hardware.camera2.utils.Decorator.invoke(Decorator.java:81)
at java.lang.reflect.Proxy.invoke(Proxy.java:397)
at $Proxy2.submitRequestList(Unknown Source)
at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:617)
at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:503)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:161)
at Control.CameraApi21Plus.captureSinglePhoto(CameraApi21Plus.java:171)
at com.CameraActivity.onClick(CameraActivity.java:108)
单人拍照功能:
public void captureSinglePhoto() {
if (mCameraSession == null && mCameraDevice == null) return;
ImageReader reader = ImageReader.newInstance(mTexturePreviewSize.getWidth(),
mTexturePreviewSize.getHeight(),
ImageFormat.JPEG, 1);
reader.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler);
Surface surface = reader.getSurface();
try {
CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
requestBuilder.addTarget(surface);
mCameraSession.stopRepeating();
mCameraSession.capture(requestBuilder.build(), sessionCaptureListener, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
private ImageReader.OnImageAvailableListener imageAvailableListener = new ImageReader.OnImageAvailableListener()
{
@Override
public void onImageAvailable(ImageReader reader) {
Image img = reader.acquireLatestImage();
}
};
private CameraCaptureSession.CaptureCallback sessionCaptureListener = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
//super.onCaptureCompleted(session, request, result);
}
};
在相机 2 中 API、
引用 CameraCaptureSession
、
的文档
If a new session is created by the camera device, then the previous
session is closed, and its associated onClosed callback will
be invoked. All of the session methods will throw an
IllegalStateException if called once the session is closed.
因此,正如文档所暗示的那样,您正在调用一个封闭的会话。找出这个。我可以帮助你们更多地编写更多代码。
另外,我希望你模仿的是 Camera2 API 样本 code.If 不是我建议你看看 it。
您只能捕获到为会话配置的表面,因此您应该在创建会话之前准备表面。
官方文档中:
IllegalArgumentException if the request targets no Surfaces or
Surfaces that are not configured as outputs for this session; ...
就像那里一样,您需要在创建会话时准备好表面 mImageReader.getSurface()
mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
...
}, null);
官方样本:
谁能告诉我我做错了什么...我想使用 SurfaceView 捕捉我有预览屏幕的图像。我能够在表面视图上显示预览。
这是我捕获图像的代码
if (mCameraSession == null && mCameraDevice == null) return;
ImageReader reader = ImageReader.newInstance(mTexturePreviewSize.getWidth(),
mTexturePreviewSize.getHeight(),
ImageFormat.JPEG, 1);
reader.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler);
Surface surface = reader.getSurface();
try {
CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
requestBuilder.addTarget(surface);
mCameraSession.capture(requestBuilder.build(), sessionCaptureListener, null);
下面是我收到的错误信息。
java.lang.IllegalArgumentException: Bad argument passed to camera service
at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.java:114)
at android.hardware.camera2.utils.CameraBinderDecorator$CameraBinderDecoratorListener.onAfterInvocation(CameraBinderDecorator.java:73)
at android.hardware.camera2.utils.Decorator.invoke(Decorator.java:81)
at java.lang.reflect.Proxy.invoke(Proxy.java:397)
at $Proxy2.submitRequestList(Unknown Source)
at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:617)
at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:503)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:161)
at Control.CameraApi21Plus.captureSinglePhoto(CameraApi21Plus.java:171)
at com.CameraActivity.onClick(CameraActivity.java:108)
单人拍照功能:
public void captureSinglePhoto() {
if (mCameraSession == null && mCameraDevice == null) return;
ImageReader reader = ImageReader.newInstance(mTexturePreviewSize.getWidth(),
mTexturePreviewSize.getHeight(),
ImageFormat.JPEG, 1);
reader.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler);
Surface surface = reader.getSurface();
try {
CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
requestBuilder.addTarget(surface);
mCameraSession.stopRepeating();
mCameraSession.capture(requestBuilder.build(), sessionCaptureListener, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
private ImageReader.OnImageAvailableListener imageAvailableListener = new ImageReader.OnImageAvailableListener()
{
@Override
public void onImageAvailable(ImageReader reader) {
Image img = reader.acquireLatestImage();
}
};
private CameraCaptureSession.CaptureCallback sessionCaptureListener = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
//super.onCaptureCompleted(session, request, result);
}
};
在相机 2 中 API、
引用 CameraCaptureSession
、
If a new session is created by the camera device, then the previous session is closed, and its associated onClosed callback will be invoked. All of the session methods will throw an IllegalStateException if called once the session is closed.
因此,正如文档所暗示的那样,您正在调用一个封闭的会话。找出这个。我可以帮助你们更多地编写更多代码。
另外,我希望你模仿的是 Camera2 API 样本 code.If 不是我建议你看看 it。
您只能捕获到为会话配置的表面,因此您应该在创建会话之前准备表面。
官方文档中:
IllegalArgumentException if the request targets no Surfaces or Surfaces that are not configured as outputs for this session; ...
就像那里一样,您需要在创建会话时准备好表面 mImageReader.getSurface()
mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
...
}, null);
官方样本: