【问题标题】:android how to draw a bitmap on canvas semi transparentandroid如何在canvas半透明上绘制位图
【发布时间】:2011-11-18 07:22:27
【问题描述】:

我尝试修改 Paint 变量,但没有成功 - 如何使位图显示为“半透明”?

【问题讨论】:

    标签: android bitmap transparency


    【解决方案1】:
    canvas.drawColor(Color.WHITE);   
    BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.loading);    
    Bitmap bm = bd.getBitmap();    
    Paint paint = new Paint();    
    paint.setAlpha(60);                             //you can set your transparent value here    
    canvas.drawBitmap(bm, 0, 0, paint);
    

    【讨论】:

    • 在 kotlin 中也能完美运行!
    【解决方案2】:
    Paint p = new Paint();
    p.setAlpha(70);
    
    Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper);
    canvas.drawBitmap(image, xPosition, yPosition, p); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2021-04-02
      • 2013-03-13
      • 2011-01-27
      • 2021-03-14
      相关资源
      最近更新 更多