Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setAspectRatio on a null object #3

Closed
SuyueLiu opened this issue Jul 13, 2022 · 5 comments
Closed

setAspectRatio on a null object #3

SuyueLiu opened this issue Jul 13, 2022 · 5 comments

Comments

@SuyueLiu
Copy link

在onCameraOpen中设置AspectRatio

com.serenegiant.usb.Size size = mCameraHelper.getPreviewSize();
if (size != null) {
    mPreviewWidth = size.width;
    mPreviewHeight = size.height;
    mCameraViewMain.setAspectRatio(mPreviewWidth, mPreviewHeight);
}

刚打开App就报错,
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.serenegiant.widget.AspectRatioSurfaceView.setAspectRatio(int, int)' on a null object reference

如果把setAspectRatio注释掉的话,会报下面的错
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.SurfaceHolder com.serenegiant.widget.AspectRatioSurfaceView.getHolder()' on a null object reference

请问大佬这个是什么问题?怎么解决呀?

@shiyinghan
Copy link
Owner

这个 mCameraViewMain 变量应该没有正确获取到,mCameraViewMain一直是null,所以一直报on a null object reference错误。
你是用的demo应用吗,还是自己写的app

@SuyueLiu
Copy link
Author

这个 mCameraViewMain 变量应该没有正确获取到,mCameraViewMain一直是null,所以一直报on a null object reference错误。 你是用的demo应用吗,还是自己写的app

我按照demo里的写法移植到自己的app里,我发现这个情况一会儿有一会儿没有

@SuyueLiu
Copy link
Author

大佬回复神速啊,还有个问题想请教一下
我想在按下拍照按钮之后,得到图像然后用算法处理,但是现在的接口是直接存储图片,请问有什么方法得到图像数据吗?

@shiyinghan
Copy link
Owner

shiyinghan commented Jul 13, 2022

拍照的时候用OutputStream,然后在回调onImageSaved里面使用OutputStream取图像数据
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageCapture.OutputFileOptions options = new ImageCapture.OutputFileOptions.Builder(outputStream).build(); mCameraHelper.takePicture(options, new ImageCapture.OnImageCaptureCallback() { @Override public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {

@SuyueLiu
Copy link
Author

拍照的时候用OutputStream,然后在回调onImageSaved里面使用OutputStream取图像数据 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageCapture.OutputFileOptions options = new ImageCapture.OutputFileOptions.Builder(outputStream).build(); mCameraHelper.takePicture(options, new ImageCapture.OnImageCaptureCallback() { @Override public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {

感谢大佬,可以了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants