如何合并两个ImageView的成一个图像在Android中? [英] How to merge two imageview into one image in Android?

查看:152
本文介绍了如何合并两个ImageView的成一个图像在Android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我放置在另一个图像视图一个图像视图,并作出单一的形象创建一个应用程序,并保存到SD卡。我运行它创建图像的应用程序,并保存到SD卡,但这个形象是blank.Both图像不显示在一个单一的图像,保存在SD card.Please任何一个可以帮助我。这里是我的code。

I'm creating an application for placing one image view on the another image view and made to single image and save into SD card. I run the application it creates image and save to SD card but this image is blank.Both images are not showing on one single image which is save in the SD card.Please can any one help me. Here is my code.

@SuppressWarnings("deprecation")
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ImageView image2 = (ImageView) findViewById(R.id.ImageViewTwo);
        final ImageView image = (ImageView) findViewById(R.id.ImageViewOne);

        mTempDir = Environment.getExternalStorageDirectory()+"/"+"TestTemp";
        File mtempFile = new File(mTempDir);
        if(!mtempFile.exists())
        {
            mtempFile.mkdir();
        }

        mSaveImageName = "Test.png";
        mBackGround = Bitmap.createBitmap(100 , 100 ,Bitmap.Config.ARGB_8888);

        image2.buildDrawingCache();
        mBackImage  = image2.getDrawingCache();
        mBackImage  = Bitmap.createBitmap(100 , 100 ,Bitmap.Config.ARGB_8888);

        image.buildDrawingCache();
        mTopImage = image.getDrawingCache();
        mTopImage = Bitmap.createBitmap(100 , 100 , Bitmap.Config.ARGB_8888);

        mCanvas = new Canvas(mBackGround);

        //mCanvas.drawBitmap(mBackImage, (mCanvas.getWidth() / 2), 0, null);
        mCanvas.drawBitmap(mBackImage ,0f , 0f , null);
        mCanvas.drawBitmap(mTopImage, 12f , 12f , null);

        try
        {
            mBitmapDrawable = new BitmapDrawable(mBackGround);

            Bitmap mNewSaving = mBitmapDrawable .getBitmap();
            String ftoSave = mTempDir + mSaveImageName;
            File mFile = new File(ftoSave);
            mFileOutputStream = new FileOutputStream(mFile);
            mNewSaving.compress(CompressFormat.PNG, 95 , mFileOutputStream);
            mFileOutputStream.flush();
            mFileOutputStream.close();

        }
        catch(FileNotFoundException  e)
        {
            e.printStackTrace();
        } 
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.i(TAG, "Image Created");



        }

在先进的感谢。

推荐答案

您有一些多余的行:

image2.buildDrawingCache();
mBackImage  = image2.getDrawingCache();
// delete next line
mBackImage  = Bitmap.createBitmap(100 , 100 ,Bitmap.Config.ARGB_8888);

image.buildDrawingCache();
mTopImage = image.getDrawingCache();
// delete next line
mTopImage = Bitmap.createBitmap(100 , 100 , Bitmap.Config.ARGB_8888);

这篇关于如何合并两个ImageView的成一个图像在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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