android - 在android中合并图像

标签 android image bitmap

如何通过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/

相关文章:

android - kotlin android中带有注释的抽象val

image - 使图像重叠,尽管被翻译

位图中的 C# 内存泄漏

c# - 以编程方式读取汽车里程表和其他汽车信息

android - 使用 GPS 的 Android 应用程序中的 NullPointerException

java - android - 倒计时后打开 Activity

c# - 将 Stream 转换为 Image 时参数无效异常

php - 保存图像仅在登录时可用

C:灰度 bmp 到 char 数组并返回

android - 如何告诉 Android 不要缩放图像?