将一些间隔图像水平添加到 Canvas 中的正确方法是什么?

What is the correct way to horizontally add some spaced image into a Canvas?

我绝对是 Android 开发新手,我有以下疑问。

我必须将一张张相邻的图像绘制成一个 Canvas 对象。

举个例子:我有这个图标(它很大,我必须调整它的大小):

所以我必须将这些图标中的 3 个并排放置(在图像和下一个图像之间添加一些白色 space)。

所以我做了这样的事情:

// Load the 2 images for the creation of the "difficulty graphic":
Bitmap chefHatOk = BitmapFactory.decodeResource(getResources(), R.drawable.chef_hat_ok);

// Where the previus image will be drawn:
Canvas canvas = new Canvas();

所以我认为我可以将之前的图像添加到 Canvas 中,这样做:

canvas.drawBitmap(smallImage, 0f, 0f, null); 

我认为第一个 0f 值表示插入图像(偏移量)之前的水平 space,如果我做错了断言,请纠正我。

那么,我如何将这些图像中的 3 张并排添加,并在一张图像和下一张图像之间留下一些白色 space?

像这样的东西应该可以工作:

Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);

int space = 10; // the space between images

for(int i = 0; i < 3; i++) {
    canvas.drawBitmap(smallImage, i * (smallImage.getWidth() + space), 0, null);
}

// do whatever you want with output

这应该可以完成工作,例如,对于 space 水平

的两个图像
public static mergeImages(Bitmap firstImage, Bitmap secondImage)
{
 Bitmap cs;
 int width, height;
 float space = 60f; // space between image horizontal

 if(firstImage.getWidth() > secondImage.getWidth()) {
 width = firstImage.getWidth() + secondImage.getWidth();
 } else {
 width = s.getWidth() + secondImage.getWidth();
 }
 height = firstImage.getHeight();

 cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

 Canvas comboImage = new Canvas(cs);
 comboImage.drawBitmap(firstImage, 0f, 0f, null);
 comboImage.drawBitmap(secondImage, firstImage.getWidth()+space, 0f, null);

 return cs; // result image
}