Skip to content Skip to sidebar Skip to footer

Android: Cropping An Image From The Bottom Up

I have an image, and I am trying to overlay a cropped version of the image over the original. Something like this: Original Overlay Image Image after the overlay image is croppe

Solution 1:

You can use this method:

Canvas.drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)

Here is my overlay method that may meet your need:

publicstatic Bitmap overlay(Bitmap base, Bitmap overlay, Float percentage) {
    Bitmap resultBitmap = Bitmap.createBitmap(base.getWidth(), base.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(resultBitmap);

    Paint paint = new Paint();

    // base bitmap
    canvas.drawBitmap(base, 0F, 0F, paint);

    // overlay bitmapint yOffset = (int) (percentage * base.getHeight());
    Rect rect = new Rect(0, yOffset, overlay.getWidth(), overlay.getHeight());
    canvas.drawBitmap(overlay, rect, rect, paint);
    return resultBitmap;
}

Post a Comment for "Android: Cropping An Image From The Bottom Up"