List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
public static void drawShade(Canvas canvas, RectF bounds) { int w = canvas.getWidth(); int h = canvas.getHeight(); Paint p = new Paint(); p.setStyle(Paint.Style.FILL); p.setColor(Color.BLACK & 0x88000000); RectF r = new RectF(); r.set(0, 0, w, bounds.top);/*from w w w .j a v a 2 s . c o m*/ canvas.drawRect(r, p); r.set(0, bounds.top, bounds.left, h); canvas.drawRect(r, p); r.set(bounds.left, bounds.bottom, w, h); canvas.drawRect(r, p); r.set(bounds.right, bounds.top, w, bounds.bottom); canvas.drawRect(r, p); }
From source file:Main.java
/** * Initializes all necessary values. Must be called once before * any other method to avoid NullPointerException. *///from ww w .j a v a 2 s . co m public static void init() { // initialize all booleans to true draw_help = true; draw_aim = true; draw_shields = true; draw_battery = true; draw_controls = true; draw_stats = true; draw_btns = true; // Initialize all Paints and set as much information as possible without // access to resources titlePaint = new Paint(); titlePaint.setTextAlign(Align.LEFT); textPaint = new Paint(); textPaint.setTextAlign(Align.LEFT); textPaint.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL)); textPaint.setAntiAlias(true); fieldPaint = new Paint(); highlightPaint = new Paint(); highlightPaint.setStyle(Paint.Style.FILL); highlightPaint.setAntiAlias(true); arrowPaint = new Paint(); arrowPaint.setStyle(Paint.Style.FILL_AND_STROKE); arrowPaint.setStrokeWidth(3); arrowPaint.setAntiAlias(true); controlPaint = new Paint(); controlPaint.setStyle(Paint.Style.STROKE); controlPaint.setStrokeWidth(5); bitmapPaint = new Paint(); bitmapPaint = new Paint(); bitmapPaint.setStrokeWidth(10); bitmapPaint.setFilterBitmap(true); bitmapPaint.setAntiAlias(true); }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int pixels, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { bitmapResult = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas canvas = new Canvas(bitmapResult); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0 + 5, 0 + 5, w - 5, h - 5); final RectF rectF = new RectF(rect); // make sure that our rounded corner is scaled appropriately final float roundPx = pixels * densityMultiplier; paint.setAntiAlias(true);// w w w . j a va2 s . c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); // canvas.drawColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); // draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // paint.setXfermode(new AvoidXfermode(Color.WHITE, 255, // AvoidXfermode.Mode.TARGET)); canvas.drawBitmap(input, 0, 0, paint); return bitmapResult; }
From source file:Main.java
public static Bitmap getScaledCircleCroppedBitmap(Bitmap bitmap, int destSize) { if (bitmap == null) return null; Bitmap output = Bitmap.createBitmap(destSize, destSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int srcSize = Math.min(bitmap.getWidth(), bitmap.getHeight()); final int srcX = (bitmap.getWidth() - srcSize) / 2; final int srcY = (bitmap.getHeight() - srcSize) / 2; final Rect srcRect = new Rect(srcX, srcY, srcX + srcSize, srcY + srcSize); final Rect destRect = new Rect(0, 0, destSize, destSize); final int color = 0xff424242; final Paint paint = new Paint(); paint.setAntiAlias(true);/* w w w. java 2 s . c o m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(destSize / 2, destSize / 2, destSize / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, srcRect, destRect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels) { maxHeight = (int) (getApplicationContext().getResources().getDisplayMetrics().density * maxHeight); float scale = bitmap.getHeight() * 1.0f / maxHeight; int newWidth = (int) (bitmap.getWidth() / scale); Bitmap output = Bitmap.createBitmap(newWidth, maxHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final Rect dstRect = new Rect(0, 0, newWidth, maxHeight); final RectF rectF = new RectF(dstRect); paint.setAntiAlias(true);// ww w. ja va2s . c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, dstRect, paint); return output; }
From source file:Main.java
public static Bitmap applyReflection(Bitmap originalImage) { final int reflectionGap = 4; int width = originalImage.getWidth(); int height = originalImage.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1);/*from w w w . j av a 2 s .c o m*/ Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(originalImage, 0, 0, null); Paint defaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
From source file:Main.java
public static BitmapDrawable writeOnDrawable(Activity actv, Resources res, int drawableId, String text, int textSize) { Bitmap bm = BitmapFactory.decodeResource(res, drawableId).copy(Bitmap.Config.ARGB_8888, true); DisplayMetrics dm = new DisplayMetrics(); actv.getWindowManager().getDefaultDisplay().getMetrics(dm); int pixelSize = (int) ((textSize * dm.scaledDensity)); if (text.length() > 2) { pixelSize = (int) ((textSize * dm.scaledDensity) * (0.5 - (text.length() / 10))); }//w w w.j a va2 s. c o m Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.WHITE); paint.setTextSize(pixelSize); paint.setTextAlign(Paint.Align.CENTER); // float adjust = paint.measureText(text); Canvas canvas = new Canvas(bm); int xPos = (int) ((bm.getWidth() / 2)); int yPos = (int) ((bm.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)); canvas.drawText(text, xPos, yPos, paint); return new BitmapDrawable(res, bm); }
From source file:Main.java
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { final int reflectionGap = 4; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1);//from w w w. j a va 2 s . c o m Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint deafalutPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
From source file:Main.java
public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) { Matrix m = new Matrix(); m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); float targetX, targetY; if (orientationDegree == 90) { targetX = bm.getHeight();// w w w. jav a 2 s. c o m targetY = 0; } else { targetX = bm.getHeight(); targetY = bm.getWidth(); } final float[] values = new float[9]; m.getValues(values); float x1 = values[Matrix.MTRANS_X]; float y1 = values[Matrix.MTRANS_Y]; m.postTranslate(targetX - x1, targetY - y1); Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint(); Canvas canvas = new Canvas(bm1); canvas.drawBitmap(bm, m, paint); return bm1; }
From source file:Main.java
public static Bitmap getDummyBitmap(int targetWidth, int targetHeight, int color) { Bitmap bitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true);/* ww w. ja va 2 s. co m*/ paint.setColor(color); canvas.drawPaint(paint); return bitmap; }