如何在将多个ImageView保存为一个位图的同时保持每个ImageView在Android中的位置? [英] How to save multiple ImageViews as one Bitmap while maintaining position of each ImageView in Android?

查看:240
本文介绍了如何在将多个ImageView保存为一个位图的同时保持每个ImageView在Android中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将三个ImageView保存为一个位图.以下代码可将三个ImageView保存为一个位图,但会将每个图像推到左上角,从而破坏了用户的图像外观.其中两个ImageView用颜色填充,另一个是实际图像.如何在将ImageView保存为一个位图的同时仍保持其在布局中的位置?

I have three ImageViews that I need to be able to save as one single Bitmap. The following code works to save the three ImageViews as one Bitmap but it pushes each image to the top left corner thus destroying the look of the image to the user. Two of the ImageViews are filled with color, the other is an actual image. How can I save the ImageViews as one Bitmap while still maintaining their position in the layout?

这是我到目前为止尝试过的:

Here's what I've tried so far:

    public void saveDrawer(){
        Bitmap mainBmp = backImage.getDrawingCache();
        Bitmap centerBmp = centerImage.getDrawingCache();
        Bitmap handleBmp = handleImage.getDrawingCache();

        Canvas canvas = new Canvas(mainBmp);
        canvas.drawBitmap(centerBmp, 1, 1, null);
        canvas.drawBitmap(handleBmp, 1, 1, null);

        OutputStream fOut = null;
        try {
            File root = new File(Environment.getExternalStorageDirectory()
                    + File.separator + "CustomDrawer" + File.separator);
            root.mkdirs();
            File sdImageMainDirectory = new File(root, "customdrawer.png");
            fOut = new FileOutputStream(sdImageMainDirectory);
            Log.d("Path", fOut.toString());
        } catch (Exception e) {
            Toast.makeText(this, "Error occured. Please try again later.",
                    Toast.LENGTH_SHORT).show();
        }

        try {
            mainBmp.compress(Bitmap.CompressFormat.PNG, 100, fOut);
            fOut.flush();
            fOut.close();
        } catch (Exception e) {
        }
    }

生成的图像应该看起来像这样:

The resulting image is supposed to look like this:

但是看起来像这样:

But instead looks like this:

推荐答案

canvas.drawBitmap(handleBmp, 1, 1, null);

那个1,1可以设置位置

that 1,1, can set the position

这篇关于如何在将多个ImageView保存为一个位图的同时保持每个ImageView在Android中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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