标签:amp draw canvas resources int sources null bit end
1、android中将图像进行透明度的处理:0-100来设置透明度来源于:http://blog.csdn.net/yanzi1225627/article/details/29661935
方式一
public static Bitmap getTransparentBitmap(Bitmap sourceImg, int number){ int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()]; sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg .getWidth(), sourceImg.getHeight());// 获得图片的ARGB值 number = number * 255 / 100; for (int i = 0; i < argb.length; i++) { argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF); } sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg .getHeight(), Bitmap.Config.ARGB_8888); return sourceImg; }
方式二:
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 ); // canvas.drawBitmap ( vBitmap , 50, 100, null ); //无透明 canvas.drawBitmap ( vBitmap , 50, 200, vPaint ); //有透明 } }
标签:amp draw canvas resources int sources null bit end
原文地址:http://www.cnblogs.com/bokeofzp/p/6051874.html