Last active
August 29, 2015 14:22
-
-
Save itzikBraun/26fedaa97a442a0487ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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