将两个位图图像(并排) [英] Combining two bitmap image (side by side)
本文介绍了将两个位图图像(并排)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何一个可以帮助两个位图图像合并成单一的位图
Can any one help to combine two bitmap images into single bitmap
在安卓(并排)。
谢谢, Yuvaraj
Thanks, Yuvaraj
推荐答案
您可以使用画布
- 看看这篇文章:
You can use Canvas
- check out this article:
<一个href="http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas">http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas
更新code。通过边做边:
Updated code to do it side by side:
public Bitmap combineImages(Bitmap c, Bitmap s) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom
Bitmap cs = null;
int width, height = 0;
if(c.getWidth() > s.getWidth()) {
width = c.getWidth() + s.getWidth();
height = c.getHeight();
} else {
width = s.getWidth() + s.getWidth();
height = c.getHeight();
}
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, c.getWidth(), 0f, null);
// this is an extra bit I added, just incase you want to save the new image somewhere and then return the location
/*String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";
OutputStream os = null;
try {
os = new FileOutputStream(loc + tmpImg);
cs.compress(CompressFormat.PNG, 100, os);
} catch(IOException e) {
Log.e("combineImages", "problem combining images", e);
}*/
return cs;
}
这篇关于将两个位图图像(并排)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文