Android循环梯度Alpha面具

前端之家收集整理的这篇文章主要介绍了Android循环梯度Alpha面具前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在 Android中的位图上绘制圆形梯度蒙版?试图生产类似于雾窗的东西.点击窗口,透明的圆圈显示窗口后面的内容.优雅地使用渐变,所以圆的中心是完全透明的,从中心越远透明度越低.这可能吗?

我是Android的新手,所以任何代码示例将不胜感激.

谢谢.

解决方法

private void drawFoggyWindowWithTransparentCircle(Canvas canvas,float circleX,float circleY,float radius) {

    // Get the "foggy window" bitmap
    BitmapDrawable foggyWindow = 
        (BitmapDrawable) getResources().getDrawable(R.drawable.foggy_window);
    Bitmap foggyWindowBmp = foggyWindow.getBitmap();

    // Create a temporary bitmap
    Bitmap tempBitmap = Bitmap.createBitmap(
            foggyWindowBmp.getWidth(),foggyWindowBmp.getHeight(),Bitmap.Config.ARGB_8888);
    Canvas tempCanvas = new Canvas(tempBitmap);

    // Copy foggyWindowBmp into tempBitmap
    tempCanvas.drawBitmap(foggyWindowBmp,null);

    // Create a radial gradient
    RadialGradient gradient = new android.graphics.RadialGradient(
            circleX,circleY,radius,0xFF000000,0x00000000,android.graphics.Shader.TileMode.CLAMP);

    // Draw transparent circle into tempBitmap
    Paint p = new Paint();
    p.setShader(gradient);
    p.setColor(0xFF000000);
    p.setXfermode(new PorterDuffXfermode(Mode.DST_OUT));
    tempCanvas.drawCircle(circleX,p);

    // Draw tempBitmap onto the screen (over what's already there)
    canvas.drawBitmap(tempBitmap,null);
}
原文链接:https://www.f2er.com/android/312063.html

猜你在找的Android相关文章