代码之家  ›  专栏  ›  技术社区  ›  Jason Hong

将二维码与图像合并

  •  -1
  • Jason Hong  · 技术社区  · 8 年前

    我正在尝试将二维码与图像合并,但运气不好。它一直给我: Java语言lang.NullPointerException:尝试调用虚拟方法“int android”。图样位图。getWidth()'在空对象引用上。

    下面是要调整大小和合并的类:

        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);
    

    请帮助:(

    编辑:nullpointerexcepion指向位图myLogo=BitmapFactory。解码资源(getResources(),R.drawable。ic_launcher_背景);

    1 回复  |  直到 8 年前
        1
  •  0
  •   Jason Hong    8 年前

    因此,我似乎尝试了我所有的可绘制图像和一些作品,有些没有,我还不确定限制的要求是什么:/