BitmapUtil.java 文件源码

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

项目:AppCommonFrame 作者:
/**
 * 获得带倒影的图片 . <br>
 * @author liulongzhenhai 2012-8-1 下午5:25:37 <br>
 * @param bitmap 图片对象
 * @return 图片
 */
public static Bitmap createReflectionImageWithOrigin(final Bitmap bitmap) {
    final int reflectionGap = 4;
    final int w = bitmap.getWidth();
    final int h = bitmap.getHeight();

    final Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    final Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false);

    final Bitmap bitmapWithReflection = Bitmap.createBitmap(w, h + h / 2, Config.ARGB_8888);

    final Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    final Paint deafalutPaint = new Paint();
    canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null);

    final Paint paint = new Paint();
    final LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight()
            + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号