在Android的叠加图像 [英] Overlay images in Android

查看:213
本文介绍了在Android的叠加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我要合并成一个两个图像。 (关于street.png顶级例如House.png)

I have two images that I want to merge into one. (Eg "House.png" on top of "street.png")

如何在Android中实现这一目标?我只是要合并的图像并将其导出到文件中。

How do i achieve this in Android? I just want to merge the images and export them to a file.

<一个href=\"http://stackoverflow.com/questions/2739971/overlay-two-images-in-android-to-set-an-imageview\">This例如图像设置为一个ImageView的,但我希望导出。

该其他例子行不通的自的Andr​​oid类是不可用的。

This example Sets the image to an ImageView but i wish to export it.
This other example does not work in Android since the classes are not available.

推荐答案

我想尝试这样的:

public static Bitmap mergeImages(Bitmap bottomImage, Bitmap topImage) {
    final Bitmap output = Bitmap.createBitmap(bottomImage.getWidth(), bottomImage
            .getHeight(), Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    paint.setAntiAlias(true);

    canvas.drawBitmap(bottomImage, 0, 0, paint);
    canvas.drawBitmap(topImage, 0, 0, paint);

    return output;
}

(没有测试过,我只是写在这里,可能是一些简单的错误在那里)

(not tested, I just wrote it here, might be some simple errors in there)

基本上,你要做的就是创建一个空的3位,借鉴它的底部图像,然后画上的图像了它。

Basically what you do is create a 3rd empty bitmap, draw the bottom image on it and then draw the top image over it.

至于保存到一个文件,这里有几个例子:安卓:位图保存到的位置

As for saving to a file, here are a few examples: Android : Bitmap save to location

这篇关于在Android的叠加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆