覆盖位图时错误android

覆盖位图时错误android

本文介绍了覆盖位图时错误android.graphics.Canvas.throwIfRecycled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于覆盖位图时错误android.graphics.Canvas.throwIfRecycled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:35