如果要将图像作为资源包括在内,最简单的方法就是自己在gimp之类的程序中编辑图像。您可以在此处添加背景,并确保它的外观,并且不必在每次加载图像时都需要处理修改图像的功能。
如果您自己无法控制图片,则可以通过执行以下操作(假设您
Bitmap名为)来修改它
image。
Bitmap imageWithBG = Bitmap.createBitmap(image.getWidth(), image.getHeight(),image.getConfig()); // Create another image the same sizeimageWithBG.eraseColor(Color.WHITE); // set its background to white, or whatever color you wantCanvas canvas = new Canvas(imageWithBG); // create a canvas to draw on the new imagecanvas.drawBitmap(image, 0f, 0f, null); // draw old image on the backgroundimage.recycle(); // clear out old image



