【发布时间】:2016-08-22 11:30:10
【问题描述】:
我得到了一个由带有 ImageView 的单个 Layout 组成的 Android 项目。
public class MainActivity extends AppCompatActivity {
/* original and stretched sized bitmaps */
private Bitmap bitmapOriginal;
private Bitmap bitmapStretched;
/* the only view */
private ImageView iv;
....
}
这个 ImageView 被这个可运行函数更新
runnable = new Runnable() {
@Override
public void run() {
iv.setImageBitmap(bitmapStretched);
}
};
runnable 由临时 JNI 函数运行,在后台线程上运行,每秒调用 60 次。
public void jniTemporizedCallback(int buf[]) {
/* set data to original sized bitmap */
bitmapOriginal.setPixels(buf, 0, origWidth, 0, 0, origWidth, origHeight);
/* calculate the stretched one */
bitmapStretched = Bitmap.createScaledBitmap(bitmapOriginal, width, height, false);
/* tell the main thread to update the image view */
runOnUiThread(runnable);
}
绘制某些帧后,应用程序崩溃并显示以下消息。
A/OpenGLRenderer: Task is already in the queue!
我猜这是因为渲染器没有完成完整渲染 ImageView 的前一帧而生气。
如果我删除runOnUiThread(runnable);,问题就会消失(显然)
如何避免这种情况?如何将我的应用程序与 openGL 渲染器同步?
我也尝试扩展 ImageView 并将画布上的位图绘制到 onDraw 函数中,但我得到了相同的结果
【问题讨论】:
-
希望对您有所帮助。 stackoverflow.com/questions/5869114/…
-
试试这个来检查之前的线程是否完成。检查这个stackoverflow.com/questions/8799373/…
标签: android multithreading bitmap opengl-es imageview