gpt4 book ai didi

android - 在android中合并图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:10:34 26 4
gpt4 key购买 nike

如何通过java编程在android中合并两个图像并保存在外部SD卡或其他地方。

最佳答案

试试下面的代码

private Bitmap joinImages(File first, File second)
{
Bitmap bmp1, bmp2;
bmp1 = BitmapFactory.decodeFile(first.getPath());
bmp2 = BitmapFactory.decodeFile(second.getPath());
if (bmp1 == null || bmp2 == null)
return bmp1;
int height = bmp1.getHeight();
if (height < bmp2.getHeight())
height = bmp2.getHeight();

Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth() + bmp2.getWidth(), height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0, 0, null);
canvas.drawBitmap(bmp2, bmp1.getWidth(), 0, null);
return bmOverlay;
}

关于android - 在android中合并图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5948886/

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