Skip to content

Instantly share code, notes, and snippets.

@itzikBraun
Last active August 29, 2015 14:22
Show Gist options
  • Save itzikBraun/26fedaa97a442a0487ff to your computer and use it in GitHub Desktop.
Save itzikBraun/26fedaa97a442a0487ff to your computer and use it in GitHub Desktop.
/**
* Constructing a bitmap that contains the given bitmaps(max is three).
*
* For given two bitmaps the result will be a half and half bitmap.
*
* For given three the result will be a half of the first bitmap and the second
* half will be shared equally by the two others.
*
* @param bitmaps Array of bitmaps to use for the final image.
* @param width width of the final image, A positive number.
* @param height height of the final image, A positive number.
* @return A Bitmap containing the given images.
* */
@Nullable public static Bitmap getMixImagesBitmap(@Size(min = 1) int width,@Size(min = 1) int height, @NonNull Bitmap...bitmaps){
if (height == 0 || width == 0) return null;
if (bitmaps.length == 0) return null;
Bitmap finalImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(finalImage);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
if (bitmaps.length == 2){
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[0], width/2, height), 0, 0, paint);
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[1], width/2, height), width/2, 0, paint);
}
else{
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[0], width/2, height), 0, 0, paint);
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[1], width/2, height/2), width/2, 0, paint);
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[2], width/2, height/2), width/2, height/2, paint);
}
return finalImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment