-1

I have a full-screen image in the form of bitmap, and I have to save it to sd card, with a company logo placed on the bottom right position, I know how to overlay a bitmap to another, but my 2nd bitmap is very small and the 1st bitmap is big I want 2nd bitmap placed on 1st bitmap at its bottom-right position.

 private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp1, new Matrix(), null);
        canvas.drawBitmap(bmp2, new Matrix(), null);
        return bmOverlay;
    }

enter image description hereso far i tried this

Android: How to overlay-a-bitmap/draw-over a bitmap?

Like in this top-right a logo on this cars image.

prashant17
  • 1,520
  • 3
  • 14
  • 23

1 Answers1

1

If you have just constant resource files that are situated in your app folder you can try to do like this. In xml layout add second ImageView and add android:translationZ="2dp" so that it is above the main background image. (This is when you are using ConstraintLayout otherwise you can replace it with FrameLayout and it will automatically do the magic.

<android.support.constraint.ConstraintLayout
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="330dp"
    >

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/overlayImage"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_margin="2dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:scaleType="centerCrop"
        android:translationZ="2dp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.94"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        app:layout_constraintVertical_bias="0.16000003" />

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/mainImage"
        android:layout_width="448dp"
        android:layout_height="190dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        />

</android.support.constraint.ConstraintLayout>

After that just add images. For the example I will use Glide (if you haven't use it before, suggesting to check it).

GlideApp.with(context)
        .load(pathToBitmap)
        .into(mainImage)

GlideApp.with(context)
        .load(pathToBitmap)
        .into(overlayImage)
aleksandrbel
  • 1,422
  • 3
  • 20
  • 38