覆盖位图时错误android.graphics.Canvas.throwIfRecycled位图、错误、android、throwIfRecycled

由网友(喵爱)分享简介:我试着去覆盖使用下面的方法在画布上的图像:Im trying to overlay images on a canvas using the following method:private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {bmOverlay = Bitmap.c...

我试着去覆盖使用下面的方法在画布上的图像:

Im trying to overlay images on a canvas using the following method:

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {

    bmOverlay = Bitmap.createBitmap(70, 70, Bitmap.Config.RGB_565);
    canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, 0, 0, null);  //line 179
    canvas.drawBitmap(bmp2, 0, 0, null);
    return bmOverlay;           
}

不过,我的应用程序不断崩溃和日志记载:

However, my app keeps crashing and the log reads:

显示java.lang.NullPointerException     在android.graphics.Canvas.throwIfRecycled(Canvas.java:954)     在android.graphics.Canvas.drawBitmap(Canvas.java:980)     在com.MyApp.overlay(MyApp.java:179)

java.lang.NullPointerException at android.graphics.Canvas.throwIfRecycled(Canvas.java:954) at android.graphics.Canvas.drawBitmap(Canvas.java:980) at com.MyApp.overlay(MyApp.java:179)

谁能帮助?

推荐答案

我有同样的trowIfRecycled例外,而试图绘制一个位图的画布。我试图在一个线程我开始画,该方案得到周围初始化前位。所以,在我的情况:位为空,我不得不找一个更好的地方做初始化。

I had the same trowIfRecycled exception while trying to draw a bitmap to a canvas. I was trying to draw in a thread I started, before the program got around to initializing the bitmap. So in my case: bitmap was null and I had to look for a better place to do the initializing.

阅读全文

相关推荐

最新文章