我是 Android 开发的新手,我有以下疑问。
我必须将一张张图片并排绘制到 Canvas 对象中。
举个例子:我有这个图标(它非常大,我必须调整它的大小):
所以我必须将其中的 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 做这样的事情:
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
关于java - 将一些间隔图像水平添加到 Canvas 中的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38162291/