我有Android应用程序,我用前置摄像头拍摄照片。我用过这里描述的方法:http://android-er.blogspot.sk/2010/12/add-overlay-on-camera-preview.html。 它适用于安卓2.3.6的Nexus S,适用于安卓4.1.1的HTC One X
使用最新的Android 4.2.2无法在Asus Nexus 7上运行,当我尝试拍照时,我会在日志中看到这个:
04-03 22:06:56.181: I/MainSSCActivity(24745): camera take picture START
04-03 22:06:56.191: E/NvOmxCamera(24952): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoMode(NvxComponent*, NvOmxCameraUserStereoMode&): Error: invalid NVX mode 0.
04-03 22:06:56.191: E/NvOmxCamera(24952): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoModeAndCaptureInfo(NvxComponent*, NvOmxCameraUserStereoMode&, NVX_STEREOCAPTUREINFO&): getCameraStereoMode failed with 0x00000000
04-03 22:06:56.191: D/NvOsDebugPrintf(24952): NvMMLiteJPEGEncSetAttribute: Incorrect value 0 for stereo capture type
04-03 22:06:56.191: E/NvOmxCameraSettings(24952): OMX_ERRORTYPE android::programStereoInfo(OMX_HANDLETYPE, const NVX_STEREOCAPTUREINFO&, android::NvxWrappers*): pNvxWrappers->OMX_SetConfigIL failed with 0x80001005
04-03 22:06:56.351: I/MainSSCActivity(24745): camera take picture END
04-03 22:06:56.391: I/MainSSCActivity(24745): ***** surface destroyed
04-03 22:06:56.401: I/hwcomposer(130): Setting interactive mode: On
04-03 22:06:56.481: E/BufferQueue(130): [SurfaceView] queueBuffer: SurfaceTexture has been abandoned!
04-03 22:06:56.491: E/SurfaceTextureClient(24952): queueBuffer: error queuing buffer to SurfaceTexture, -19
04-03 22:06:56.491: E/NvOmxCamera(24952): Queue Buffer Failed
04-03 22:06:56.491: A/libc(24952): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 25019 (Binder_3)
04-03 22:06:56.491: D/MainSSCActivity(24745): RAW bytes: null
04-03 22:06:56.491: D/MainSSCActivity(24745): shutter
04-03 22:06:56.591: I/DEBUG(128): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-03 22:06:56.591: I/DEBUG(128): Build fingerprint: 'google/nakasig/tilapia:4.2.2/JDQ39/573038:user/release-keys'
04-03 22:06:56.591: I/DEBUG(128): Revision: '0'
04-03 22:06:56.591: I/DEBUG(128): pid: 24952, tid: 25019, name: Binder_3 >>> /system/bin/mediaserver <<<
04-03 22:06:56.591: I/DEBUG(128): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
04-03 22:06:56.701: I/DEBUG(128): r0 00000027 r1 deadbaad r2 4022f258 r3 00000000
04-03 22:06:56.701: I/DEBUG(128): r4 00000000 r5 42de4d6c r6 415dc640 r7 411b7c58
04-03 22:06:56.701: I/DEBUG(128): r8 411cfe30 r9 415dc8c8 sl 00000000 fp 00000001
04-03 22:06:56.701: I/DEBUG(128): ip 40be2de4 sp 42de4d68 lr 402022f9 pc 401fe992 cpsr 60000030
04-03 22:06:56.701: I/DEBUG(128): d0 0000000000000000 d1 000000007fc00000
04-03 22:06:56.701: I/DEBUG(128): d2 3fb15bd900000000 d3 3f114ee7df28fa15
04-03 22:06:56.701: I/DEBUG(128): d4 0000000000000000 d5 3ff0000000000000
04-03 22:06:56.701: I/DEBUG(128): d6 0000000541000000 d7 7fc0000000000000
04-03 22:06:56.701: I/DEBUG(128): d8 0000000000000000 d9 0000000000000000
04-03 22:06:56.701: I/DEBUG(128): d10 0000000000000000 d11 0000000000000000
到目前为止,我真的不知道什么是错的,以及如何解决它。 有谁能够帮我?提前谢谢。
答案 0 :(得分:2)
myPictureCallback_JPG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] bytes, Camera arg1) {
Log.d(TAG, "bytes.length: " + bytes.length);
String image = Base64.encodeToString(bytes, Base64.NO_WRAP);
Log.i(TAG, "base64 image: " + image);
String url = "javascript:takePicture('" + image + "');";
wv.loadUrl(url);
camera.stopPreview();
camera.release();
camera = null;
surfaceView.setVisibility(View.INVISIBLE);
wv.setVisibility(View.VISIBLE);
viewControl.setVisibility(View.INVISIBLE);
}
};
答案 1 :(得分:0)
尝试这样做,它可能会有效。覆盖活动中的“onPause”方法并调用“stopPreview()”。看起来表面甚至在你调用stopPreview()之前就被破坏了,因此错误“SurfaceTexture已被放弃!”。
@Override
public void onPause(Bundle savedInstanceState) {
super.onPause(savedInstanceState);
if(camera != null)
camera.stopPreview();
}
当应用程序传递给Camera驱动程序的Surface(缓冲区)在驱动程序仍在访问它时被销毁时会发生这种情况。
如果有效,请告诉我。如果这不起作用,请将整个logcat从相机应用程序的开头发布到关闭应用程序的位置。
答案 2 :(得分:0)
这解决了我的问题:
我使用的是mcamera.setOneShotPreviewCallback(mPreviewCallback);从相机获取图片。
我已经通过mCamera.takePicture(null,null,mPictureCallback)改变了它;
在mPictureCallBack中我处理了jpeg,在我的情况下,我拍摄了另一张照片,重新开始拍摄照片之间的预览(stopPreview和startPreview)。
顺便说一句,我的预览版基于样本Api 17 / android-sdks / samples / android-17 / ApiDemos / src / com / example / android / apis / graphics / CameraPreview。