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

The Archive Base Latest Questions

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

I want to create a combined image with two different images by overlapping. For

  • 0

I want to create a combined image with two different images by overlapping.

For this My code is

  ImageView image = (ImageView) findViewById(R.id.imageView1);
  Drawable drawableFore = getResources().getDrawable(R.drawable.foreg);
  Drawable drawableBack = getResources().getDrawable(R.drawable.backg);

  Bitmap bitmapFore = ((BitmapDrawable) drawableFore).getBitmap();
  Bitmap bitmapBack = ((BitmapDrawable) drawableBack).getBitmap();

  Bitmap scaledBitmapFore = Bitmap.createScaledBitmap(bitmapFore, 35, 35, true);
  Bitmap scaledBitmapBack = Bitmap.createScaledBitmap(bitmapBack, 45, 45, true);

  Bitmap combineImages = overlay(scaledBitmapBack, scaledBitmapFore);

  image.setImageBitmap(combineImages);

overlay() method is

public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2)
{
 try
 {
   Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(),  bmp1.getConfig());
   Canvas canvas = new Canvas(bmOverlay);
   canvas.drawBitmap(bmp1, new Matrix(), null);
   canvas.drawBitmap(bmp2, 0, 0, null);
   return bmOverlay;
 } catch (Exception e)
 {
    // TODO: handle exception
  e.printStackTrace();
  return null;
 }
}

case 1 :overlay method returns null in this case.

case 2: But when I switch images like I use background image for setting in foreground and foreground image for setting in background then code works fine.

but I want the first case should work properly but it is not.
I am not getting why this is happening.

Please Help

  • 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-27T10:45:43+00:00Added an answer on May 27, 2026 at 10:45 am

    I think it happens, because the 2nd bitmap is bigger in size. So try this:

    public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2)
    {
     try
     {
       int maxWidth = (bmp1.getWidth() > bmp2.getWidth() ? bmp1.getWidth() : bmp2.getWidth());
       int maxHeight = (bmp1.getHeight() > bmp2.getHeight() ? bmp1.getHeight() : bmp2.getHeight());
       Bitmap bmOverlay = Bitmap.createBitmap(maxWidth, maxHeight,  bmp1.getConfig());
       Canvas canvas = new Canvas(bmOverlay);
       canvas.drawBitmap(bmp1, 0, 0, null);
       canvas.drawBitmap(bmp2, 0, 0, null);
       return bmOverlay;
    
     } catch (Exception e)
     {
        // TODO: handle exception
      e.printStackTrace();
      return null;
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want create image animation , i have 50 images with png format now
I have 3 different images and want to create a sprite using CSS. I
I have two files. I want to create pdf with these two files. does
I want to create user profile with image. That user can upload his photo,
I want to combine some images with PHPGD to create a CSS Sprite dynamically,
Is it possible to create a combined column graph and line graph with different
I want to create a stored procedure to do some combined keyword search using
This is how I save images. [HttpPost] public ActionResult Create(HttpPostedFileBase file) { if (file
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert

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.