ReflectView.java 文件源码

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

项目:TvLauncher 作者:
/**
 * Set the bitmap reflection
 *
 * @param bitmap
 * @return
 */
public static Bitmap createReflectedImage(Bitmap bitmap, int reflectHeight) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (height <= reflectHeight) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height
            - reflectHeight, width, reflectHeight, matrix, true);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, reflectHeight,
            Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(reflectionImage, 0, 0, null);
    LinearGradient shader = new LinearGradient(0, 0, 0,
            bitmapWithReflection.getHeight(), 0x80ffffff, 0x00ffffff,
            TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, 0, width, bitmapWithReflection.getHeight(), paint);
    return bitmapWithReflection;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号