0

What I want: Create image with two bitmap, under first bitmap put second bitmap.


At this moment I use this code

public static Bitmap combineImages(Bitmap background, Bitmap foreground, float disFromTheTopPercent) {

        int width = background.getWidth(), height = background.getHeight();
        Bitmap cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas comboImage = new Canvas(cs);
        background = Bitmap.createScaledBitmap(background, width, height, true);
        comboImage.drawBitmap(background, 0, 0, null);

        int top = (int) (disFromTheTopPercent * height);
        int left = 0;

        comboImage.drawBitmap(foreground, left, top, null);

        return cs;
    }

Bad is that it associated actually with height, weight, and dpi from my smartfon.

Its different when I use smartfone with 5 inch screen and 6 inch screen, regardless diferent screen this must looke same.

Visual presentation

Thanks for help!

Dr Mido
  • 2,414
  • 4
  • 32
  • 72
Developer534255
  • 121
  • 1
  • 9

1 Answers1

1

Try this code:

public static Bitmap combineImages(Bitmap c, Bitmap s) {
    Bitmap cs;
    int width, height;

    width = s.getWidth();
    height = c.getHeight() + s.getHeight();

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas comboImage = new Canvas(cs);

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

    return cs;
}
Demonick
  • 2,116
  • 3
  • 30
  • 40