Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:45:01+00:00 2026-05-27T15:45:01+00:00

I am having code for combining two image and show them together in a

  • 0

I am having code for combining two image and show them together in a canvas as follows. Can you say how to store that as a single image.

public class ChoosePictureComposite extends Activity implements OnClickListener {

    static final int PICKED_ONE = 0;
    static final int PICKED_TWO = 1;

    boolean onePicked = false;
    boolean twoPicked = false;

    Button choosePicture1, choosePicture2;
    ImageView compositeImageView;

    Bitmap bmp1, bmp2;
    Canvas canvas;
    Paint paint;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        compositeImageView = (ImageView) this
                .findViewById(R.id.CompositeImageView);

        choosePicture1 = (Button) this.findViewById(R.id.ChoosePictureButton1);
        choosePicture2 = (Button) this.findViewById(R.id.ChoosePictureButton2);

        choosePicture1.setOnClickListener(this);
        choosePicture2.setOnClickListener(this);
    }

    public void onClick(View v) {

        int which = -1;

        if (v == choosePicture1) {
            which = PICKED_ONE;
        } else if (v == choosePicture2) {
            which = PICKED_TWO;
        }

        Intent choosePictureIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(choosePictureIntent, which);
    }

    protected void onActivityResult(int requestCode, int resultCode,
            Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);

        if (resultCode == RESULT_OK) {
            Uri imageFileUri = intent.getData();

            if (requestCode == PICKED_ONE) {
                bmp1 = loadBitmap(imageFileUri);
                onePicked = true;
            } else if (requestCode == PICKED_TWO) {
                bmp2 = loadBitmap(imageFileUri);
                twoPicked = true;
            }

            if (onePicked && twoPicked) {
                Bitmap drawingBitmap = Bitmap.createBitmap(bmp1.getWidth(),
                        bmp1.getHeight(), bmp1.getConfig());
                canvas = new Canvas(drawingBitmap);
                paint = new Paint();
                canvas.drawBitmap(bmp1, 90, 0, paint);
            //  paint.setXfermode(new PorterDuffXfermode(
                    //  android.graphics.PorterDuff.Mode.MULTIPLY));
                canvas.drawBitmap(bmp2, 30, 40, paint);


                 compositeImageView.setImageBitmap(drawingBitmap);
            }
        }
    }

    private Bitmap loadBitmap(Uri imageFileUri) {
        Display currentDisplay = getWindowManager().getDefaultDisplay();

        float dw = currentDisplay.getWidth();
        float dh = currentDisplay.getHeight();

        Bitmap returnBmp = Bitmap.createBitmap((int) dw, (int) dh,
                Bitmap.Config.ARGB_4444);

        try {
            // Load up the image's dimensions not the image itself
            BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
            bmpFactoryOptions.inJustDecodeBounds = true;
            returnBmp = BitmapFactory.decodeStream(getContentResolver()
                    .openInputStream(imageFileUri), null, bmpFactoryOptions);

            int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight / dh);
            int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / dw);

            Log.v("HEIGHTRATIO", "" + heightRatio);
            Log.v("WIDTHRATIO", "" + widthRatio);

            // If both of the ratios are greater than 1, one of the sides of the
            // image is greater than the screen
            if (heightRatio > 1 && widthRatio > 1) {
                if (heightRatio > widthRatio) {
                    // Height ratio is larger, scale according to it
                    bmpFactoryOptions.inSampleSize = heightRatio;
                } else {
                    // Width ratio is larger, scale according to it
                    bmpFactoryOptions.inSampleSize = widthRatio;
                }
            }

            // Decode it for real
            bmpFactoryOptions.inJustDecodeBounds = false;
            returnBmp = BitmapFactory.decodeStream(getContentResolver()
                    .openInputStream(imageFileUri), null, bmpFactoryOptions);
        } catch (FileNotFoundException e) {
            Log.v("ERROR", e.toString());
        }

        return returnBmp;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:45:01+00:00Added an answer on May 27, 2026 at 3:45 pm

    Try this:

    public class Aura extends Activity {
      protected static final String TAG = Aura.class.getName();
      private static String mTempDir;
      Bitmap mBackImage, mTopImage, mBackground, mInnerImage, mNewSaving;
      Canvas mComboImage;
      FileOutputStream mFileOutputStream;
      BitmapDrawable mBitmapDrawable;
      private String mCurrent = null;
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aura);
    
        mTempDir = Environment.getExternalStorageDirectory() + "/" + "Aura" + "/";
        mCurrent = "Aura.png";
        prepareDirectory();
    
        mBackground = Bitmap.createBitmap(604, 1024, Bitmap.Config.ARGB_8888);
        mBackImage = BitmapFactory.decodeResource(getResources(), R.drawable.aura);
        mTopImage = BitmapFactory.decodeResource(getResources(), R.drawable.test);
        mInnerImage = BitmapFactory.decodeResource(getResources(), R.drawable.anothertest);
    
        mComboImage = new Canvas(mBackground);
        mComboImage.drawBitmap(mBackImage, 0f, 0f, null);
        mComboImage.drawBitmap(mTopImage, 0f, 0f, null);
        mComboImage.drawBitmap(mInnerImage, 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);
              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());
            }
          }
        });
      }//onCreate
    
      private boolean prepareDirectory() {
        try {
          if (makeDirectory()) {
            return true;
          } else {
            return false;
          }
        } catch (Exception e) {
          e.printStackTrace();
          Toast.makeText(this, getString(R.string.sdcard_error), 1000).show();
          return false;
        }
      }
    
      private boolean makeDirectory() {
        File mTempFile = new File(mTempDir);
        if (!mTempFile.exists()) {
          mTempFile.mkdirs();
        }
    
        if (mTempFile.isDirectory()) {
          File[] mFiles = mTempFile.listFiles();
          for (File mEveryFile : mFiles) {
            if (!mEveryFile.delete()) {
              System.out.println(getString(R.string.failed_to_delete) + mEveryFile);
            }
          }
        }
        return (mTempFile.isDirectory());
      }
    
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((!(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT)
            && keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)) {
          onBackPressed();
        }
        return super.onKeyDown(keyCode, event);
      }
    
      public void onBackPressed() {
        finish();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm often having code written as follows try: self.title = item.title().content.string except AttributeError, e:
Just like the title says I am having problems combining two classes. Altough this
I'm having trouble combining audio and video into one file. The Python code looks
Having code: struct B { int* a; B(int value):a(new int(value)) { } B():a(nullptr){} B(const
Having code: Date::Date(const char* day, const char* month, const char* year):is_leap__(false) { my_day_ =
Having code: int** a = new int*[2]; a[0] = new int(1); a[1] = new
I am having code NSString *cellValue1 = [products1 objectAtIndex:indexPath.row]; when i try to print
I'm using VS2010 Ultimate. Having code: //file IntSet.h #include stdafx.h #pragma once /*Class representing
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
Having this code... var b = new ReadOnlyCollection<int>(new[] { 2, 4, 2, 2 });

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.