欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

在Android中创建投影特效,android投影特效,private Bitm

来源: javaer 分享于  点击 20554 次 点评:36

在Android中创建投影特效,android投影特效,private Bitm


private Bitmap getReflection(Bitmap bitmap) {    Bitmap reflection = reflections.get(bitmap);    if (reflection == null) {        // We're cropping the height of the reflection to 80        int reflectionH = 80;        reflection = Bitmap.createBitmap(bitmap.getWidth(),                reflectionH, Bitmap.Config.ARGB_8888);        Bitmap blurryBitmap = Bitmap.createBitmap(bitmap, 0,                bitmap.getHeight() - reflectionH,                bitmap.getWidth(), reflectionH);        // cheap and easy scaling algorithm; down-scale it, then        // upscale it. The filtering during the scale operations        // will blur the resulting image        blurryBitmap = Bitmap.createScaledBitmap(                Bitmap.createScaledBitmap(                        blurryBitmap,blurryBitmap.getWidth() / 2,                        blurryBitmap.getHeight() / 2, true),                blurryBitmap.getWidth(), blurryBitmap.getHeight(), true);        // This shader will hold a cropped, inverted,        // blurry version of the original image        BitmapShader bitmapShader = new BitmapShader(blurryBitmap,                TileMode.CLAMP, TileMode.CLAMP);        Matrix invertMatrix = new Matrix();        invertMatrix.setScale(1f, -1f);        invertMatrix.preTranslate(0, -reflectionH);        bitmapShader.setLocalMatrix(invertMatrix);        // This shader holds an alpha gradient        Shader alphaGradient = new LinearGradient(0, 0, 0, reflectionH,                0x80ffffff, 0x00000000, TileMode.CLAMP);        // This shader combines the previous two, resulting in a        // blurred, fading reflection        ComposeShader compositor = new ComposeShader(bitmapShader,                alphaGradient, PorterDuff.Mode.DST_IN);        Paint reflectionPaint = new Paint();        reflectionPaint.setShader(compositor);        // Draw the reflection into the bitmap that we will return        Canvas canvas = new Canvas(reflection);        canvas.drawRect(0, 0, reflection.getWidth(),                reflection.getHeight(), reflectionPaint);    }    return reflection;
相关栏目:

用户点评