将 QR 码与图像合并

Merging QR Code with an image

我正在尝试将二维码与图像合并,但没有成功。它一直给我: java.lang.NullPointerException: 尝试在空对象引用上调用虚拟方法 'int android.graphics.Bitmap.getWidth()'。

这里是 class 调整大小和合并:

    public Bitmap mergeBitmaps(Bitmap myLogo, Bitmap bitmap){
    Bitmap combined = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    Canvas canvas = new Canvas(combined);
    int canvasWidth = canvas.getWidth();
    int canvasHeight = canvas.getHeight();
    canvas.drawBitmap(bitmap, new Matrix(), null);

    Bitmap resizeLogo = Bitmap.createScaledBitmap(myLogo, canvasWidth / 5, canvasHeight / 5, true);
    int centreX = (canvasWidth - resizeLogo.getWidth()) /2;
    int centreY = (canvasHeight - resizeLogo.getHeight()) / 2;
    canvas.drawBitmap(resizeLogo, centreX, centreY, null);
    return combined;
}

下面是我将其推送到 ImageView 的方式:

    Bitmap myLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background);
    Bitmap merge = mergeBitmaps(myLogo, bitmap);

    imageView.setImageBitmap(merge);

请帮忙:(

编辑:空指针异常指向位图 myLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background);

看来我尝试了所有可绘制的图像,有些可以,有些不行,我不确定限制的要求是什么:/