android 绘制在路径(Path)剪切中的平铺图像
1 public static Bitmap TileClipPath(Bitmap src,Path path,int w,int h) 2 { 3 BitmapDrawable drawable = new BitmapDrawable(src); 4 drawable.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT ); 5 drawable.setDither(true); 6 7 Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 8 : Bitmap.Config.RGB_565; 9 Bitmap bitmap = Bitmap.createBitmap(w, h, config); 10 Canvas canvas = new Canvas(bitmap); 11 drawable.setBounds(0, 0, w, h); 12 drawable.draw(canvas); 13 14 Bitmap outbitmap = Bitmap.createBitmap(w, h, config); 15 Canvas outcanvas = new Canvas(outbitmap); 16 17 outcanvas.drawARGB(0, 0, 0, 0); 18 Paint paint = new Paint(); 19 paint.setAntiAlias(true); 20 paint.setColor(0xff424242); 21 outcanvas.drawPath(path, paint); 22 paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 23 outcanvas.drawBitmap(bitmap, 0, 0, paint); 24 25 return outbitmap; 26 }
原创文章欢迎转载,转载请注明出处:http://www.cnblogs.com/zhouchanwen