从相机的影像融合与可绘制图像

问题描述:

我正尝试合并2图像,一个是从摄像头的位图,第二个是png格式存储在可绘制文件。我所做的,我用两个图像为位图,我试图用帆布,这样的合并它们:

I´m trying to merge 2 images, one is bitmap from camera, second one is .png file stored in drawables. What I did was that I used both images as bitmaps and I tried to merge them by using canvas, something like this:

Bitmap topImage = BitmapFactory.decodeFile("gui.png");
Bitmap bottomImage = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);

Canvas canvas = new Canvas(bottomImage);
canvas.drawBitmap(topImage, 0, 0, null);

不过,我不断收到位图大小超过VM预算的错误所有的时间。我试图几乎一切,但是,它仍然不断抛出此错误。是否有合并2图像的另一种方式?我需要做的很简单 - 我需要拍照并保存与存储在可绘制的PNG图片合并。例如这个程序是非常接近我所需要的 - https://play.google.com/store/apps/details?id=com.hl2.hud&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5obDIuaHVkIl0.

感谢:)

请参阅下面的code用于组合两个图像。
该方法返回相结合的位图

See the below code for combining two images. This method returns combined bitmap

public Bitmap combineImages(Bitmap frame, Bitmap image) {
        Bitmap cs = null;
        Bitmap rs = null;

        rs = Bitmap.createScaledBitmap(frame, image.getWidth() + 50,
                image.getHeight() + 50, true);

        cs = Bitmap.createBitmap(rs.getWidth(), rs.getHeight(),
                Bitmap.Config.RGB_565);

        Canvas comboImage = new Canvas(cs);

        comboImage.drawBitmap(image, 25, 25, null);
        comboImage.drawBitmap(rs, 0, 0, null);
        if (rs != null) {
            rs.recycle();
            rs = null;
        }
        Runtime.getRuntime().gc();
        return cs;
    }

您可以改变高度和宽度按您的要求
希望这将有助于...

You can change height and width as per your requirements Hope this will help...