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 8322141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:16:44+00:00 2026-06-08T23:16:44+00:00

I want to merge two bitmaps, here is my code // Camera arg conversion

  • 0

I want to merge two bitmaps, here is my code

// Camera arg conversion to Bitmap
                    Bitmap cameraBitmap = BitmapFactory.decodeByteArray(arg0, 0,
                            arg0.length);
                    Bitmap back = Bitmap.createBitmap(cameraBitmap.getWidth(),
                        cameraBitmap.getHeight(), Bitmap.Config.ARGB_8888);
                    Canvas cam = new Canvas(back);
                    cam.drawBitmap(cameraBitmap, matrix, null);


                    // FrameLayout to Bitmap
                    FrameLayout mainLayout = (FrameLayout) findViewById(R.id.frame);
                    Bitmap foreground = Bitmap.createBitmap(mainLayout.getWidth(),
                            mainLayout.getHeight(), Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas(foreground);
                    mainLayout.draw(c);

                    Bitmap cs = null;
                    cs = Bitmap.createBitmap(foreground.getWidth(), cameraBitmap.getHeight(), Bitmap.Config.ARGB_8888); 

                    Canvas comboImage = new Canvas(cs); 
                    comboImage.drawBitmap(cameraBitmap, 0f, 0f, null); 
                    comboImage.drawBitmap(foreground, 0f, cameraBitmap.getHeight(), null); 

                    FileOutputStream fos = null;
                    try {
                        fos = new FileOutputStream(file);
                        if (fos != null) {
                            cs.compress(Bitmap.CompressFormat.PNG, 90, fos);
                            fos.close();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }   

The camera image should become background, and foreground as top image. I’ve tried from
Combining 2 Images in Android using Canvas but it didn’t help me. Any idea.? Thanks

  • 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-06-08T23:16:46+00:00Added an answer on June 8, 2026 at 11:16 pm

    From your example, you forgot to add the next lines:

     comboImage.drawBitmap(c, 0f, 0f, null); 
     comboImage.drawBitmap(s, 0f, c.getHeight(), null);
    

    In your example above you don’t draw your image in the canvas, and that is the problem.
    You can think that your canvas i your sketchbook. For now you didn’t paint anything, and you ask yourself, way I can’t see any colors.

    So, for my advice, first create the two bitmaps, then, do the next thing:

    c.drawBitmap(cameraBitmap, top point, left point, null);
    c.drawBitmap(foreground, top point, left point, null); 
    

    You can also do this by first create the drawable objects from your bitmaps, like in the next code:

    Drawable cameraBitmap = BitmapDrawable(cameraBitmap);
    Drawable foreground= BitmapDrawable(foreground);
    

    Then when you have the drawable objects, you can set thier bounds, and that way you set where do you want to show that image.

    cameraBitmap.setBounds(left, top, right, bottom);
    foreground.setBounds(left, top, right, bottom);
    

    and finally draw that on the canvas:

    cameraBitmap.draw(canvas);
    foreground.draw(canvas);
    

    EDIT:

    This is an example, use this to understand your implementation:

        Bitmap bitmap = null;
        try {
    
            bitmap = Bitmap.createBitmap(500, 500, Config.ARGB_8888);
            Canvas c = new Canvas(bitmap);
            Resources res = getResources();
    
    
            Bitmap bitmap1 = BitmapFactory.decodeResource(res, R.drawable.test1); //blue
    
            Bitmap bitmap2 = BitmapFactory.decodeResource(res, R.drawable.test2); //green
            Drawable drawable1 = new BitmapDrawable(bitmap1);
            Drawable drawable2 = new BitmapDrawable(bitmap2);
    
    
            drawable1.setBounds(100, 100, 400, 400);
            drawable2.setBounds(150, 150, 350, 350);
            drawable1.draw(c);
            drawable2.draw(c);
    
    
        } catch (Exception e) {
        }
        return bitmap;
    

    This is what I get from the code above:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two bitmap images ..and i need to merge the bitmaps with precise
I want to merge two arrays and replace the text with strtr function. I
I want to merge two branches that have been separated for a while and
I want to merge two cells in excel using pyExcelerator , ws.write_merge(r1=0,r2=1,c1=0, c2=0, label='test1',
What i'm trying to do is pretty simple.I want to merge two maps. Say
I'm using classic ASP in my project. I want to merge two XMLs together.
I have to array and I want to merge this two array with a
I want to merge all data in two arraylist in c#. Some data in
I have two objects and I want to merge them: public class Foo {
I have two mysql tables and i want to merge the results of these

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.