List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
public static Bitmap createScaledBitmap(Bitmap bitmap, int width, int height) { Bitmap background = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); float originalWidth = bitmap.getWidth(), originalHeight = bitmap.getHeight(); Canvas canvas = new Canvas(background); float scale = Math.max(width / originalWidth, height / originalHeight); float xTranslation = 0.0f, yTranslation = (height - originalHeight * scale) / 2.0f; if (originalWidth < originalHeight) { // scale = height / originalHeight; xTranslation = (width - originalWidth * scale) / 2.0f; yTranslation = 0.0f;// www.j a v a 2 s. c o m } Matrix transformation = new Matrix(); transformation.postTranslate(xTranslation, yTranslation); transformation.preScale(scale, scale); Paint paint = new Paint(); paint.setFilterBitmap(true); canvas.drawBitmap(bitmap, transformation, paint); return background; }
From source file:Main.java
/** * Create circle image./* w w w .jav a2 s .c o m*/ * * @param bitmap Bitmap to be cropped * @param resColor Resource color * @param strokeWidth Thickness of stroke * @return Returns the circle image with border */ public static Bitmap getCircleImage(Bitmap bitmap, int resColor, int strokeWidth) { // create Bitmap to draw Bitmap mBitmap = Bitmap.createBitmap(bitmap.getWidth() + 8, bitmap.getHeight() + 8, Bitmap.Config.ARGB_8888); // create Rect to hold image final Rect mRec = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); // create Canvas Canvas mCanvas = new Canvas(mBitmap); mCanvas.drawARGB(0, 0, 0, 0); // create Paint final Paint mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); mPaint.setAntiAlias(true); // get the half size of the image int mHalfWidth = bitmap.getWidth() / 2; int mHalfHeight = bitmap.getHeight() / 2; // draw circle mCanvas.drawCircle((mHalfWidth + 4), (mHalfHeight + 4), Math.min(mHalfWidth, mHalfHeight), mPaint); // unknown mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // draw the image mCanvas.drawBitmap(bitmap, mRec, mRec, mPaint); // set border mode mPaint.setXfermode(null); // set stroke mPaint.setStyle(Paint.Style.STROKE); // set stroke color mPaint.setColor(resColor); // set stroke width mPaint.setStrokeWidth(strokeWidth); // draw stroke mCanvas.drawCircle((mHalfWidth + 4), (mHalfHeight + 4), Math.min(mHalfWidth, mHalfHeight), mPaint); // return the circle image return mBitmap; }
From source file:Main.java
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { final int reflectionGap = 4; int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1);//from www. j a v a2 s. c o m Bitmap reflectionImage; reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint defaultPaint = new Paint(); canvas.drawRect(0, h, w, h + reflectionGap, defaultPaint); canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
From source file:Main.java
public static Bitmap getRoundCornerBitmap(Bitmap bitmap, int radius) { // Canvas canvas = new Canvas(bitmap); // Rect r =new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); // RectF rect = new RectF(r); // Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER)); // canvas.drawRoundRect(rect, 3f, 3f, paint); // // canvas.drawBitmap(bitmap, 0, 0, paint); // return bitmap; Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); // final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = radius; paint.setAntiAlias(true);/*from w w w . j a v a 2 s .c o m*/ // canvas.drawARGB(0, 0, 0, 0); // paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, new Paint(Paint.ANTI_ALIAS_FLAG)); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
/** * Creates the Paint object for drawing the translucent overlay outside the * crop window./*www. j ava 2s . c o m*/ * * @param context the Context * @return the new Paint object */ public static Paint newBackgroundPaint(Context context) { final Paint paint = new Paint(); paint.setColor(Color.parseColor(DEFAULT_BACKGROUND_COLOR_ID)); return paint; }
From source file:Main.java
public static Bitmap getUnreadMarker(int width, int radius, int color) { if (width <= 0) { return null; }/*w w w . ja v a 2 s . co m*/ Bitmap dest = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(dest); Paint p = new Paint(); p.setColor(color); p.setAntiAlias(true); canvas.drawCircle(width / 2, width / 2, radius, p); return dest; }
From source file:Main.java
public static Bitmap getColoredBitmap(Bitmap colorBitmap, int color) { Bitmap grayscaleBitmap = toGrayscale(colorBitmap); Paint pp = new Paint(); PorterDuffColorFilter frontFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY); pp.setColorFilter(frontFilter);/*from www. j av a2 s . c o m*/ Canvas cc = new Canvas(grayscaleBitmap); cc.drawBitmap(grayscaleBitmap, 0, 0, pp); return grayscaleBitmap; }
From source file:Main.java
public static Bitmap forceConfig565(Bitmap original) { Bitmap convertedBitmap = original;/* ww w . j a va 2 s .com*/ if (original.getConfig() != Bitmap.Config.RGB_565) { convertedBitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(convertedBitmap); Paint paint = new Paint(); paint.setColor(Color.BLACK); canvas.drawBitmap(original, 0, 0, paint); if (convertedBitmap != original) { original.recycle(); } } return convertedBitmap; }
From source file:Main.java
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { if (bitmap == null) { return null; }/* www . j ava 2 s . co m*/ final int reflectionGap = 4; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height * 2 / 3, width, height / 3, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 3), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint defaultPaint = new Paint(); defaultPaint.setColor(Color.TRANSPARENT); canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x88ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawRect(0, height, width, bitmapWithReflection.getHeight(), paint); return bitmapWithReflection; }
From source file:Main.java
public static Bitmap getRoundBitmap(Bitmap bmp, float roundDP) { // roundDP *= Constants.screen_density; Bitmap bmpOut = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888); Canvas c = new Canvas(bmpOut); final Paint p = new Paint(); final RectF rectF = new RectF(0, 0, bmp.getWidth(), bmp.getHeight()); p.setAntiAlias(true);/*from w ww . java 2 s . c om*/ c.drawARGB(0, 0, 0, 0); p.setColor(Color.BLACK); c.drawRoundRect(rectF, roundDP, roundDP, p); p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); c.drawBitmap(bmp, 0, 0, p); return bmpOut; }