Java 在画布上水平添加一些间隔图像的正确方法是什么?

Java 在画布上水平添加一些间隔图像的正确方法是什么?,java,android,android-canvas,android-image,android-bitmap,Java,Android,Android Canvas,Android Image,Android Bitmap,我是Android开发的新手,我有以下疑问 我必须将图像一个接一个地绘制到画布对象中 让我们来看一个例子:我有一个图标(它非常大,我必须调整它的大小): 因此,我必须将其中的3个图标一个挨着一个放置(在图像和下一个图像之间添加一些空白) 所以我做了这样的事情: // Load the 2 images for the creation of the "difficulty graphic": Bitmap chefHatOk = BitmapFactory.decodeResource(get

我是Android开发的新手,我有以下疑问

我必须将图像一个接一个地绘制到画布对象中

让我们来看一个例子:我有一个图标(它非常大,我必须调整它的大小):

因此,我必须将其中的3个图标一个挨着一个放置(在图像和下一个图像之间添加一些空白)

所以我做了这样的事情:

// 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.drawBitmap(smallImage, 0f, 0f, null); 
因此,我认为我可以将上一张图像添加到画布中,这样做:

// 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.drawBitmap(smallImage, 0f, 0f, null); 
我认为第一个0f值表示插入图像之前的水平空间(偏移量),如果我的断言错误,请更正我


那么,我如何才能将其中的3个图像一个接一个地添加,在一个图像和下一个图像之间留下一些空白呢?

类似的方法应该可以:

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
Bitmap output=Bitmap.createBitmap(宽度、高度、Bitmap.Config.ARGB_8888);
画布=新画布(输出);
整数空间=10;//图像之间的空间
对于(int i=0;i<3;i++){
drawBitmap(smallImage,i*(smallImage.getWidth()+空格),0,null);
}
//用输出做任何你想做的事情

这应该可以完成这项工作,例如对于两个空间水平的图像

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
}