我建造了一座surfaceView类来显示来自摄像机的图像。我花了一段时间才得到它的工作,但我添加了一些吐司,对话框和一些布尔变量来在AnnotateSurface类和Activity类中进行调试。我在if语句中使用其中的一个来运行线程以将图像绘制到表面(如果它是真的)(这是阻止它工作的原因)。安卓:布尔不工作correclty - 斯特兰奇
if(bitmapState){
drawSomething(canvas);
}
我得到它的工作,但只有在我发现布尔值bitmapState被重置为false后。它被初始化为false,但在getBitmap方法中将其更改为true。这是编辑布尔变量的唯一方法。
setBitmap方法中的toast显示“true”,但是当我从activity类调用getStuff方法时,它将其显示为false,并且run方法中的if语句在我使用以下代码时也不起作用:
if (surfaceState == bitmapState == true) {
drawSomething(canvas);
}
这真是令人困惑,因为所有其他布尔值的行为都是正确的。如果有人有任何见解,我很乐意听到它。
public class AnnotateSurface extends SurfaceView implements Callback, Runnable {
// create a holder to manage the surface of the view
SurfaceHolder ourHolder;
// Create a thread
Thread ourThread = null;
// Create a boolean to determine when to stop the animation
boolean isRunning = false;
boolean surfaceState = false;
boolean bitmapState = false;
public static Bitmap bmpIm = null;
Context c;
Canvas canvas;
int ws, hs;
public AnnotateSurface(Context context) {...
}
public AnnotateSurface(Context context, AttributeSet attrs) {...
}
public AnnotateSurface(Context context, AttributeSet attrs, int defStyle) {...
}
// create a method to pause the thread
public void pause() {...
}
public void resume() {...
}
// create a method to resume the thread
public void setBitmap(Bitmap b) {
bmpIm = b;
// bmpIm = AnnotateImage.bmpAnnotate;
// isRunning = true;
bitmapState = true;
Toast toast = new Toast(c);
Toast.makeText(c, Boolean.toString(bitmapState), Toast.LENGTH_LONG)
.show();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {...
}
@Override
public void surfaceCreated(SurfaceHolder holder) {...
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
surfaceState = false;
}
// @Override
public void drawSomething(Canvas canvas) {...
}
public String getstuff() {
String Data = "not drawing" + Boolean.toString(this.bitmapState)
+ Boolean.toString(surfaceState) + Boolean.toString(isRunning)
+ Integer.toString(ws) + Integer.toString(hs);
return Data;
}
public Bitmap getstuffImage() {...
}
@Override
public void run() {...
}
}
嗯,变量本身没有变化,所以其他的东西都变了......我注意到'bitmapState'不是私人的,你是否在改变它的任何其他类?还张贴在哪里以及如何创建您的敬酒。最后,这样的:'吐司面包=新吐司(C);'从未使用过... – Sam 2013-02-28 18:41:21
你指的是可以在不使用这里被删除的敬酒,我声明,但从未使用过它。在这之下的敬酒返回true。我没有在任何其他类中编辑它,该活动没有布尔变量。这是活动类的敬酒..... String tx = ourSurfaceView.getstuff(); \t \t \t吐司吐司=新吐司(本); \t \t \t Toast.makeText(此,TX,Toast.LENGTH_LONG).show(); – frage 2013-02-28 18:58:15
我意识到,我弯了腰上宣布祝酒有作为 – frage 2013-02-28 18:58:50