Android 图片处理
jopen
10年前
android圆角处理 public static Bitmap getRoundedCornerbitmap(Bitmap bitmap,float roundpx) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint p = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectf = new RectF(rect); p.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); p.setColor(color); canvas.drawRoundRect(rectf, roundpx, roundpx, p); p.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, p); return output; } 倒影效果: public static Bitmap creatReflection(Bitmap bitmap) { final int reflectionGap = 4; int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h/2, w, h/2, matrix, false); Bitmap bitreflection = Bitmap.createBitmap(w, h+h/2, Config.ARGB_8888); Canvas canvas = new Canvas(bitreflection); Paint p = new Paint(); canvas.drawRect(0, h, w, h+reflectionGap, p); canvas.drawBitmap(reflectionImage, 0, h+reflectionGap, null); Paint p1 = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitreflection.getHeight()+reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); p1.setShader(shader); p1.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN)); canvas.drawRect(0, h, w, bitreflection.getHeight()+reflectionGap, p1); return bitreflection; }