I am working on a distributed application of android.I have splitted a single image into lets say 4 parts and then processed it. Now I want to combine 4 bitmap images into a single image. How can i do that?
我正在研究android的分布式应用程序。我将一个图像分割成4个部分,然后进行处理。现在我要将4个位图图像合并到一个图像中。我怎么做呢?
3 个解决方案
#1
17
Bitmap[] parts = new Bitmap[4];
Bitmap result = Bitmap.createBitmap(parts[0].getWidth() * 2, parts[0].getHeight() * 2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
for (int i = 0; i < parts.length; i++) {
canvas.drawBitmap(parts[i], parts[i].getWidth() * (i % 2), parts[i].getHeight() * (i / 2), paint);
}
Something like this =)
这样的=)
#2
6
Following piece of code will do the trick for you to combine four bitmaps in one. Call this method 3 times to combine the four images.
下面的代码可以帮助您将四个位图组合在一起。调用此方法3次,以组合这4个图像。
Step 1:Combine first two images
第一步:合并前两张图片
Step 2:Combine the renaming two images
步骤2:合并重命名的两个图像
Step 3:Combine the the two new created bitmaps
步骤3:合并两个新创建的位图
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, 0, 0, null);
return bmOverlay;
}
#3
0
You need to create a function of bitmap type. That is, it returns a bitmap data type. The function should have an argument of data type Bitmap which is an array.
您需要创建位图类型的函数。也就是说,它返回位图数据类型。函数应该有一个数据类型位图的参数,位图是一个数组。
下载演示
You will pass your images to the function as array of bitmap. This is our function to merge not only four images but any size of images.
你将把你的图像作为位图数组传递给函数。这是我们的功能,不仅要合并四个图像,还要合并任意大小的图像。
private Bitmap mergeMultiple(Bitmap[] parts){
Bitmap result = Bitmap.createBitmap(parts[0].getWidth() * 2, parts[0].getHeight() * 2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
for (int i = 0; i < parts.length; i++) {
canvas.drawBitmap(parts[i], parts[i].getWidth() * (i % 2), parts[i].getHeight() * (i / 2), paint);
}
return result;
}
Finally you are done.. Read more here
最后你做. .点击这里了解更多内容
#1
17
Bitmap[] parts = new Bitmap[4];
Bitmap result = Bitmap.createBitmap(parts[0].getWidth() * 2, parts[0].getHeight() * 2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
for (int i = 0; i < parts.length; i++) {
canvas.drawBitmap(parts[i], parts[i].getWidth() * (i % 2), parts[i].getHeight() * (i / 2), paint);
}
Something like this =)
这样的=)
#2
6
Following piece of code will do the trick for you to combine four bitmaps in one. Call this method 3 times to combine the four images.
下面的代码可以帮助您将四个位图组合在一起。调用此方法3次,以组合这4个图像。
Step 1:Combine first two images
第一步:合并前两张图片
Step 2:Combine the renaming two images
步骤2:合并重命名的两个图像
Step 3:Combine the the two new created bitmaps
步骤3:合并两个新创建的位图
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, 0, 0, null);
return bmOverlay;
}
#3
0
You need to create a function of bitmap type. That is, it returns a bitmap data type. The function should have an argument of data type Bitmap which is an array.
您需要创建位图类型的函数。也就是说,它返回位图数据类型。函数应该有一个数据类型位图的参数,位图是一个数组。
下载演示
You will pass your images to the function as array of bitmap. This is our function to merge not only four images but any size of images.
你将把你的图像作为位图数组传递给函数。这是我们的功能,不仅要合并四个图像,还要合并任意大小的图像。
private Bitmap mergeMultiple(Bitmap[] parts){
Bitmap result = Bitmap.createBitmap(parts[0].getWidth() * 2, parts[0].getHeight() * 2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
for (int i = 0; i < parts.length; i++) {
canvas.drawBitmap(parts[i], parts[i].getWidth() * (i % 2), parts[i].getHeight() * (i / 2), paint);
}
return result;
}
Finally you are done.. Read more here
最后你做. .点击这里了解更多内容