ImageUtils.java 文件源码

java
阅读 36 收藏 0 点赞 0 评论 0

项目:chat-sdk-android-push-firebase 作者:
/**
 * 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;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号