gpt4 book ai didi

android - 拍照卡在 Android 2.3.3 上

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:18 26 4
gpt4 key购买 nike

我有一些在 Android 2.1 和 2.2 中工作的拍照代码。但是这些代码在 Android 2.3 中失效了。花时间解决了这个问题但没有成功,我想在这里寻求帮助。

我拍照的代码流程是这样的:

创建一个类 Camlayer extends SurfaceView

public class CamLayer extends SurfaceView implements SurfaceHolder.Callback {
private void init(Context context){
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mCamera = Camera.open();
}

public CamLayer(Context context) {
super(context);
init(context);
}

public CamLayer(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Log.i(TAG+".surfaceChanged", "being called!");
Log.i(TAG+".surfaceChanged", "w="+w);
Log.i(TAG+".surfaceChanged", "h="+h);
if (isPreviewRunning) {
mCamera.stopPreview();
}

try {
mCamera.setPreviewDisplay(holder);
mCamera.setPreviewCallback(mPreviewCallback);
} catch (IOException e) {
Log.e(TAG+".surfaceCreated", "mCamera.setPreviewDisplay(holder);");
}

Camera.Parameters p = mCamera.getParameters();
setOptimalSize(p, w, h, SIZEOFPREVIEW);
setOptimalSize(p, w, h, SIZEOFPICTURE);
mCamera.setParameters(p);

mCamera.startPreview();
isPreviewRunning = true;
}

public void takePicture(){
Log.i(TAG+".takePicture", "being called!");
mCamera.takePicture(null, null, mPictureCallback);
Log.i(TAG+".takePicture", "call ended!");
}
}

CamLayer.takePicture() 会被外部类调用启动。

问题是在Android 2.3.3 上,takePicture 会挂起,所以发现ANR 问题。在 /data/anr/traces.txt 中,可以找到以下内容。如您所见,native_takePicture 永远不会返回。

达尔维克线程:

(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 NATIVE

| group="main" sCount=1 dsCount=0 obj=0x40022170 self=0xce68

| sysTid=2411 nice=0 sched=0/0 cgrp=default handle=-1345006464

at android.hardware.Camera.native_takePicture(Native Method)

at android.hardware.Camera.takePicture(Camera.java:746)

at android.hardware.Camera.takePicture(Camera.java:710)

at oms.cj.tube.camera.CamLayer.takePicture(CamLayer.java:256)

at oms.cj.tube.camera.DefineColor.takePicture(DefineColor.java:61)

at oms.cj.tube.camera.DefineColor.onKeyUp(DefineColor.java:71)

at android.view.KeyEvent.dispatch(KeyEvent.java:1280)

at android.app.Activity.dispatchKeyEvent(Activity.java:2078)

at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:16
66)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2571)

at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2546)

at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loop(Looper.java:123)

at android.app.ActivityThread.main(ActivityThread.java:3691)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:507)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)

at dalvik.system.NativeStart.main(Native Method)

有人遇到同样的问题吗?并知道如何修复它?

最佳答案

我还观察到 mCamera.takePicture(null, null, handler) 卡住。我尝试在调用 takePicture() 之前清除预览处理程序:mCamera.setPreviewCallback(null),现在它可以工作了。

关于android - 拍照卡在 Android 2.3.3 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6535652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com