【发布时间】:2021-03-16 14:51:52
【问题描述】:
我想在 runnable 中绘制位图但不工作。 该代码给出了应用程序的退出错误。 我在代码中注释了非工作部分。
private Runnable updateTimerThread = new Runnable() {
public void run() {
// This code block dont run. Application exit error.
bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
canvas.drawArc(rect, 0F, 360F, true, paint);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
customHandler.postDelayed(this, showTime);
timeSwapBuff += timeInMilliseconds;
customHandler.removeCallbacks(updateTimerThread);
}
};
【问题讨论】:
-
“不要跑”是什么意思?你真的调用了这段代码来运行吗?您是否将此
Runnable的实例提交给执行器服务? -
这段代码在 protected void onCreate(Bundle savedInstanceState) { } 中正常运行。但是这段代码不能在私有 Runnable updateTimerThread = new Runnable() { } 中运行。我尝试但程序给出应用程序退出错误。我想在 Runnable 中绘制位图。
标签: java android bitmap draw runnable