Android Bitmap 透明度(Picture 透明度)

Android可透过 Paint 物件,来设定Bitmap透明度.

Java 程式范例 :

public class helloWorld extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView( new drawCanvas(this) );
    }
 
    class drawCanvas extends View {
        public drawCanvas(Context context) {
            super(context);
        }
 
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
 
            // 取得Resource 图片的Bitmap
            Bitmap vBitmap = BitmapFactory.decodeResource( this.getResources()
                                                         , R.drawable.icon
                                                         );
 
            // 建立Paint 物件
            Paint vPaint = new Paint();
            vPaint .setStyle( Paint.Style.STROKE );   //空心
            vPaint .setAlpha( 75 );   // Bitmap透明度(0 ~ 100)
 
            canvas.drawBitmap ( vBitmap , 50, 100, null );  //无透明
            canvas.drawBitmap ( vBitmap , 50, 200, vPaint );  //有透明
        }
    }
}

转自:http://disanji.net/2010/12/11/android-bitmap-picture/

你可能感兴趣的:(Android学习笔记)