Thursday, April 7, 2011

how to combine two image in android

Bitmap mBackImage, mTopImage, mBackground;
 BitmapDrawable mBitmapDrawable;
private static String mTempDir;
 private String mCurrent = null;
FileOutputStream mFileOutputStream;


In OnCreate:

 mTempDir = Environment.getExternalStorageDirectory() + "/" + getResources().getString(R.string.externaldir) + "/";
        mCurrent = "Aura.png";
mBackground = Bitmap.createBitmap(604, 1024, Bitmap.Config.ARGB_8888);
        mBackImage = BitmapFactory.decodeResource(getResources(), R.drawable.aura);
        mTopImage = BitmapFactory.decodeResource(getResources(), R.drawable.test);
       
        mComboImage = new Canvas(mBackground);
        mComboImage.drawBitmap(mBackImage, 0f, 0f, null);
        mComboImage.drawBitmap(mTopImage, 0f, 0f, null);
        mFileOutputStream = null;


 mSave.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                Log.v(TAG, "Save Tab Clicked");
                try
                {
                    mBitmapDrawable = new BitmapDrawable(mBackground);
                    Bitmap mNewSaving = ((BitmapDrawable)mBitmapDrawable).getBitmap();
                    String FtoSave = mTempDir + mCurrent;
                    File mFile = new File(FtoSave);
                    mFileOutputStream = new FileOutputStream(mFile);
                    mNewSaving.compress(CompressFormat.PNG, 95, mFileOutputStream);
                    mFileOutputStream.flush();
                    mFileOutputStream.close();
                }
                catch (FileNotFoundException e)
                {
                    Log.v(TAG, "FileNotFoundExceptionError " + e.toString());
                }
                catch (IOException e)
                {
                    Log.v(TAG, "IOExceptionError " + e.toString());
                }
            }
        });

No comments:

Post a Comment