List of usage examples for android.graphics Paint setStyle
public void setStyle(Style style)
From source file:Main.java
public static Bitmap setupFrame(Bitmap bitmap, int width, int color) { if (bitmap.getWidth() <= width * 2 || bitmap.getHeight() <= width * 2) { return bitmap; }// w w w .j a v a 2s. c o m Bitmap bp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bp); canvas.drawBitmap(bitmap, 0, 0, new Paint()); Paint paint = new Paint(); paint.setColor(color); paint.setStrokeWidth(width); paint.setStyle(Style.STROKE); canvas.drawRect(0, 0, canvas.getWidth() - width, canvas.getHeight() - width, paint); bitmap.recycle(); return bp; }
From source file:Main.java
/** * Create circle image.//ww w.j a v a 2 s . c om * * @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
static void mutatePaint(Paint paint, int color, float strokeWidth, Paint.Style style) { paint.setColor(color);/*from www. j a va 2 s.c o m*/ paint.setStrokeWidth(strokeWidth); paint.setStyle(style); }
From source file:Main.java
public static void drawCircleBorder(Canvas canvas, int radius, int w, int y) { Paint paint = new Paint(); paint.setAntiAlias(true);/*from ww w .j a va 2 s . co m*/ paint.setFilterBitmap(true); paint.setDither(true); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(mBorderThickness); canvas.drawCircle(w / 2, y / 2, radius, paint); }
From source file:Main.java
/** * Creates the Paint object for drawing the corners of the border * // w w w .j av a2 s . c o m * @param context the Context * @return the new Paint object */ public static Paint newCornerPaint(Context context) { // Set the line thickness for the crop window border. final float lineThicknessPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CORNER_THICKNESS_DP, context.getResources().getDisplayMetrics()); final Paint cornerPaint = new Paint(); cornerPaint.setColor(DEFAULT_CORNER_COLOR); cornerPaint.setStrokeWidth(lineThicknessPx); cornerPaint.setStyle(Paint.Style.STROKE); return cornerPaint; }
From source file:Main.java
public static Bitmap getTextImage(String text, float size, int width, int height) { final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Paint paint = new Paint(); final Canvas canvas = new Canvas(bmp); canvas.drawColor(Color.WHITE); paint.setColor(Color.BLACK);//from w ww.j a v a2 s. c om paint.setStyle(Style.FILL); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(size); paint.setTypeface(Typeface.DEFAULT); canvas.drawText(text, width / 2, height / 2, paint); return bmp; }
From source file:Main.java
/** * Creates the Paint object for drawing the crop window border. * /* w w w .ja v a 2 s . c o m*/ * @param context the Context * @return new Paint object */ public static Paint newBorderPaint(Context context) { // Set the line thickness for the crop window border. final float lineThicknessPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_LINE_THICKNESS_DP, context.getResources().getDisplayMetrics()); final Paint borderPaint = new Paint(); borderPaint.setColor(Color.parseColor(SEMI_TRANSPARENT)); borderPaint.setStrokeWidth(lineThicknessPx); borderPaint.setStyle(Paint.Style.STROKE); return borderPaint; }
From source file:com.irccloud.android.data.model.Avatar.java
public static Bitmap generateBitmap(String text, int textColor, int bgColor, boolean isDarkTheme, int size, boolean round) { Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); if (bitmap != null) { Canvas c = new Canvas(bitmap); Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); p.setStyle(Paint.Style.FILL); if (isDarkTheme || !round) { p.setColor(bgColor);/*w w w . j ava2 s . c o m*/ if (round) c.drawCircle(size / 2, size / 2, size / 2, p); else c.drawColor(bgColor); } else { float[] hsv = new float[3]; Color.colorToHSV(bgColor, hsv); hsv[2] *= 0.8f; p.setColor(Color.HSVToColor(hsv)); c.drawCircle(size / 2, size / 2, (size / 2) - 2, p); p.setColor(bgColor); c.drawCircle(size / 2, (size / 2) - 2, (size / 2) - 2, p); } TextPaint tp = new TextPaint(Paint.ANTI_ALIAS_FLAG); tp.setTextAlign(Paint.Align.CENTER); tp.setTypeface(font); tp.setTextSize((int) (size * 0.65)); tp.setColor(textColor); if (isDarkTheme || !round) { c.drawText(text, size / 2, (size / 2) - ((tp.descent() + tp.ascent()) / 2), tp); } else { c.drawText(text, size / 2, (size / 2) - 4 - ((tp.descent() + tp.ascent()) / 2), tp); } return bitmap; } else { return null; } }
From source file:Main.java
/** * The most useful answer about text drawing ever. http://stackoverflow.com/a/32081250 *//* ww w . j av a 2 s.c o m*/ @Nullable public static Bitmap createTypefaceBitmap(final Context context, @NonNull final String text, final int color, final float textSizePx) { final Typeface robotoMedium = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf"); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setTypeface(robotoMedium); paint.setStyle(Paint.Style.FILL); paint.setColor(color); paint.setTextSize(textSizePx); final Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); Bitmap bitmap = null; if (!bounds.isEmpty()) { final int width = bounds.width(); final int height = bounds.height(); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); final float x = bounds.left; final float y = height - bounds.bottom; final Canvas canvas = new Canvas(bitmap); canvas.drawText(text, x, y, paint); } return bitmap; }
From source file:Main.java
public static Bitmap buildSequence(Context context, String text) { Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444); Canvas myCanvas = new Canvas(myBitmap); Paint paint = new Paint(); //Typeface font = Typeface.createFromAsset(context.getAssets(),"fonts/7LED.ttf"); paint.setAntiAlias(true);//from ww w .ja v a2 s . c o m paint.setSubpixelText(true); //paint.setTypeface(font); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.YELLOW); paint.setTextSize(65); paint.setTextAlign(Paint.Align.CENTER); myCanvas.drawText(text, 80, 60, paint); return myBitmap; }