List of usage examples for android.graphics Paint setShadowLayer
public void setShadowLayer(float radius, float dx, float dy, int shadowColor)
From source file:Main.java
private static Paint getTextPaint(float size) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShadowLayer(1, 1, 1, 0xFF000000); paint.setColor(0xFFFFFFFF);/* www.j a va 2 s. com*/ paint.setTextAlign(Align.CENTER); paint.setTextSize(size); paint.setTypeface(Typeface.DEFAULT); return paint; }
From source file:Main.java
public static Paint getScoreColor() { Paint paint = new Paint(); paint.setColor(Color.WHITE);/*from w w w. j a va 2 s . c o m*/ paint.setTextSize(80); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setShadowLayer(3, 5, 5, Color.BLACK); return paint; }
From source file:Main.java
public static Paint getGameOverColor() { Paint paint = new Paint(); paint.setColor(Color.WHITE);//from w w w . j a va 2 s. c o m paint.setTextSize(80); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setShadowLayer(2, 3, 3, Color.GRAY); return paint; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int backgroundColor, int borderColor) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth() + 12, bitmap.getHeight() + 12, Bitmap.Config.ARGB_8888);//from ww w. ja v a2 s.c o m Canvas canvas = new Canvas(output); //canvas.drawARGB(Color.alpha(backgroundColor), Color.red(backgroundColor), Color.green(backgroundColor), Color.blue(backgroundColor)); Paint borderPaint = new Paint(); borderPaint.setAntiAlias(true); borderPaint.setColor(borderColor); borderPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); borderPaint.setShadowLayer(2.0f, 0.0f, 2.0f, Color.BLACK); int centerWidth = output.getWidth() / 2; int centerHeight = output.getHeight() / 2; canvas.drawCircle(centerWidth, centerHeight, ((centerWidth + centerHeight) / 2) - 4, borderPaint); Paint paint = new Paint(); paint.setAntiAlias(true); Rect rectS = new Rect(0, 0, output.getWidth() - 12, output.getHeight() - 12); Rect rectD = new Rect(0, 0, output.getWidth(), output.getHeight()); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(bitmap, rectS, rectD, paint); return output; }
From source file:Main.java
public static Bitmap addLabelToBitmap(Bitmap src, String label) { float densityFactor = Resources.getSystem().getDisplayMetrics().density; final float textPadding = src.getWidth() * 0.05f; Bitmap result = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint textPaint = new Paint(); textPaint.setAntiAlias(true);/*ww w.j av a 2s.c om*/ textPaint.setTextSize(12 * densityFactor); textPaint.setColor(Color.WHITE); textPaint.setStrokeWidth(2 * densityFactor); textPaint.setShadowLayer(1 * densityFactor, 0, 0, Color.BLACK); float textWidth = textPaint.measureText(label); float scaleFactor = (src.getWidth() - textPadding * 2) / textWidth; canvas.drawBitmap(src, 0, 0, textPaint); canvas.save(); canvas.scale(scaleFactor, scaleFactor); float textPosX = (src.getWidth() / scaleFactor - textWidth) / 2; float textPosY = (src.getHeight() - textPadding) / scaleFactor; canvas.drawText(label, textPosX, textPosY, textPaint); canvas.restore(); return result; }
From source file:Main.java
public static Bitmap drawTextCenterToBitmap(Bitmap bitmap, String text, int textSize, int textColor) { android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/*from www . ja v a2s.c o m*/ // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(textColor); // text size in pixels paint.setTextSize(textSize); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); //int x = (bitmap.getWidth() - bounds.width()) / 2; //int y = (bitmap.getHeight() + bounds.height()) / 2; //draw text to the bottom int x = (bitmap.getWidth() - bounds.width()) / 10 * 5; int y = (bitmap.getHeight() + bounds.height()) / 10 * 5; canvas.drawText(text, x, y, paint); return bitmap; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) { android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }//from w ww.ja v a 2 s. c o m bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (21)); //* scale)); // text shadow paint.setShadowLayer(2f, 1f, 1f, Color.WHITE); int x = bitmap.getWidth() - 150;//bounds.width()) - 150; int y = bitmap.getHeight() - 27;//bounds.height()) - 30; canvas.drawRect(x, y, x + 150, y + 27, paint); canvas.drawText(gText, x, y + 20, paint); return bitmap; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) { //Resources resources = gContext.getResources(); //float scale = resources.getDisplayMetrics().density; android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/*from w ww. j a va2s . co m*/ // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (21)); //* scale)); // text shadow paint.setShadowLayer(2f, 1f, 1f, Color.WHITE); // draw text to the Canvas center //Rect bounds = new Rect(); //paint.getTextBounds(gText, 0, gText.length(), bounds); int x = bitmap.getWidth() - 150;//bounds.width()) - 150; int y = bitmap.getHeight() - 27;//bounds.height()) - 30; // fill canvas.drawRect(x, y, x + 150, y + 27, paint); canvas.drawText(gText, x, y + 20, paint); return bitmap; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId); Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; }/* w w w .ja v a 2 s . c o m*/ // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #808080 paint.setColor(Color.rgb(127, 127, 127)); // text size in pixels paint.setTextSize((int) (14 * scale * 5)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(gText, 0, gText.length(), bounds); // int x = (bitmap.getWidth() - bounds.width()) / 2; // int y = (bitmap.getHeight() + bounds.height()) / 2; //draw text to the bottom int x = (bitmap.getWidth() - bounds.width()) / 10 * 9; int y = (bitmap.getHeight() + bounds.height()) / 10 * 9; canvas.drawText(gText, x, y, paint); return bitmap; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context mContext, int resourceId, String mText) { try {/*from ww w. j a v a 2 s . co m*/ Resources resources = mContext.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, resourceId); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; } // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(77, 77, 77)); // text size in pixels paint.setTextSize((int) (13 * scale)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.DKGRAY); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(mText, 0, mText.length(), bounds); int x = (int) ((bitmap.getWidth() - bounds.width()) / 4); int y = (int) ((bitmap.getHeight() + bounds.height()) / 4); canvas.drawText(mText, x * scale, y * scale, paint); return bitmap; } catch (Exception e) { e.printStackTrace(); } return null; }