gpt4 book ai didi

android - 合并两个位图图像(并排)

转载 作者:IT老高 更新时间:2023-10-28 23:16:56 26 4
gpt4 key购买 nike

任何人都可以帮助将两个位图图像组合成一个位图

在安卓中(并排)。

谢谢,尤瓦拉杰

最佳答案

您可以使用 Canvas - 查看这篇文章:

http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas

更新代码以并行执行:

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;
}

关于android - 合并两个位图图像(并排),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4863518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com