画像をリソースとして含める場合は、gimpなどのプログラムで自分で画像を編集するのが最も簡単です。そこに背景を追加して、それがどのように見えるかを確認し、ロードされるたびに画像を変更する処理能力を使用する必要はありません.
自分で画像を制御できない場合は、Bitmap
が呼び出されたと仮定して、次のようにして画像を変更できますimage
。
Bitmap imageWithBG = Bitmap.createBitmap(image.getWidth(), image.getHeight(),image.getConfig()); // Create another image the same size
imageWithBG.eraseColor(Color.WHITE); // set its background to white, or whatever color you want
Canvas canvas = new Canvas(imageWithBG); // create a canvas to draw on the new image
canvas.drawBitmap(image, 0f, 0f, null); // draw old image on the background
image.recycle(); // clear out old image