List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
public static Bitmap createRoundedBottomBitmap(Context context, int width, int height, int color) { Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); //color = 0x80424242; // FIXME final Paint paint = new Paint(); final int roundPxInt = convertDipsToPixels(context, ROUND_DIPS); final Rect rect = new Rect(0, 0, width, height - roundPxInt); final RectF rectF = new RectF(rect); final Rect rectRound = new Rect(roundPxInt, height - roundPxInt, width - roundPxInt, height); final RectF rectFRound = new RectF(rectRound); paint.setAntiAlias(true);// w w w. j ava 2 s . co m paint.setColor(color); canvas.drawARGB(0, 0, 0, 0); // Corners Rect oval = new Rect(0, height - 2 * roundPxInt, 2 * roundPxInt, height); RectF ovalF = new RectF(oval); canvas.drawArc(ovalF, 90.0f, 90.0f, true, paint); oval = new Rect(width - 2 * roundPxInt, height - 2 * roundPxInt, width, height); ovalF = new RectF(oval); canvas.drawArc(ovalF, 0.0f, 90.0f, true, paint); // Big and small rectangles canvas.drawRect(rectF, paint); canvas.drawRect(rectFRound, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { if (bitmap == null) { return null; }//from w w w . j a v a2s . co m 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); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
/** * convert Bitmap to round corner/*from w w w.j a va 2s . co m*/ * * @param bitmap * @return */ public static Bitmap toRoundCorner(Bitmap bitmap) { int height = bitmap.getHeight(); int width = bitmap.getHeight(); Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, width, height); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xff424242); //paint.setColor(Color.TRANSPARENT); canvas.drawCircle(width / 2, height / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundAngleImage(Bitmap bitmap, int pixels, boolean recycleOld) { Bitmap output = null;// ww w . ja v a 2s . com if (bitmap != null && !bitmap.isRecycled()) { output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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 = pixels; paint.setAntiAlias(true); paint.setFilterBitmap(true); canvas.drawARGB(0, 0, 0, 0); // paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); if (recycleOld) bitmap.recycle(); return output; } return output; }
From source file:Main.java
public static Bitmap getBitmap(Bitmap background, Bitmap contour, float alpha) { Paint paint = new Paint(); paint.setAntiAlias(true);/*from w ww . ja v a 2 s .co m*/ paint.setColor(Color.WHITE); paint.setDither(false); Bitmap bitmap = Bitmap.createBitmap(contour.getWidth(), contour.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Matrix m = new Matrix(); m.setScale(contour.getWidth() * 1.0f / background.getWidth(), contour.getHeight() * 1.0f / background.getHeight()); paint.setAlpha((int) (alpha * 0xff)); canvas.drawBitmap(background, m, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); paint.setAlpha(0xff); canvas.drawBitmap(contour, 0, 0, paint); return bitmap; }
From source file:Main.java
private static Bitmap getResizeBitmap(View view, Bitmap bitmap) { Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / sScaleFactor), (int) (view.getMeasuredHeight() / sScaleFactor), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft() / sScaleFactor, -view.getTop() / sScaleFactor); canvas.scale(1 / sScaleFactor, 1 / sScaleFactor); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bitmap, 0, 0, paint); return overlay; }
From source file:Main.java
public static Bitmap getCircularBitmapImage(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle();//from www .j a v a 2s. co m } Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; }
From source file:Main.java
/** * Method to remove color in a Bitmap, creating a gray scale image. * * @param bmpOriginal The original Bitmap. * @return The gray scale Bitmap./*w w w .ja v a 2s . c o m*/ */ public static Bitmap toGrayscale(Bitmap bmpOriginal) { Bitmap bmpGrayscale = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmpGrayscale); Paint paint = new Paint(); paint.setAntiAlias(true); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm); paint.setColorFilter(colorMatrixColorFilter); canvas.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }
From source file:Main.java
public static Bitmap clipRoundCornerBitmap(Bitmap bitmap, float radius, int borderColor) { if (bitmap == null) { return null; }// ww w . jav a 2 s.c om final int h = bitmap.getHeight(); final int w = bitmap.getWidth(); final Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(borderColor); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static byte[] makeFontBitmap(String font, String code, int size, float[] arrayOfPos) { Log.v(TAG, String.format("makeFontBitmap called(Java): font=%s code=%s", font, code)); Canvas c = new Canvas(); Paint p = new Paint(); // Log.v(TAG, "get density"); float density = context.getResources().getDisplayMetrics().density; Log.v(TAG, String.format("makeFontBitmap density: %f", density)); p.setTextSize((float) size * density); p.setAntiAlias(true);/*from w w w . ja v a2s.co m*/ Rect textBounds = new Rect(); p.getTextBounds(code, 0, code.length(), textBounds); Log.v(TAG, String.format("makeFontBitmap textBounds: %d,%d,%d,%d", textBounds.left, textBounds.top, textBounds.right, textBounds.bottom)); Rect textBoundsAxA = new Rect(); String axa = String.format("A%sA", code); p.getTextBounds(axa, 0, axa.length(), textBoundsAxA); Rect textBoundsAA = new Rect(); String aa = "AA"; p.getTextBounds(aa, 0, aa.length(), textBoundsAA); // cache.distDelta = Vec2(0, 0); arrayOfPos[0] = textBounds.left; arrayOfPos[1] = textBounds.top; // cache.srcWidth = Vec2(16, 16); arrayOfPos[2] = textBounds.width(); arrayOfPos[3] = textBounds.height(); // cache.step = 16; // arrayOfPos[4] = textBounds.width() + 1; arrayOfPos[4] = textBoundsAxA.width() - textBoundsAA.width(); if (textBounds.width() == 0 || textBounds.height() == 0) { Log.v(TAG, "makeFontBitmap: empty"); return null; } Bitmap b = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888); c.setBitmap(b); Rect r = new Rect(0, 0, textBounds.width(), textBounds.height()); // p.setColor(Color.RED); p.setARGB(0, 0, 0, 0); c.drawRect(r, p); p.setARGB(255, 255, 255, 255); // Log.v(TAG, "makeFontBitmap: drawText"); c.drawText(code, -textBounds.left, -textBounds.top, p); Log.v(TAG, String.format("makeFontBitmap: w=%.2f h=%.2f", arrayOfPos[2], arrayOfPos[3])); ByteBuffer buf = ByteBuffer.allocate(textBounds.width() * textBounds.height() * 4); // ByteBuffer buf = ByteBuffer.allocate(b.getRowBytes()); Log.v(TAG, String.format("makeFontBitmap: b.getRowBytes() %d", b.getRowBytes())); buf.position(0); b.copyPixelsToBuffer(buf); Log.v(TAG, String.format("makeFontBitmap results: capacity=%d", buf.capacity())); // byte bytes[] = buf.array(); // for (int i = 0; i < size * size * 2; i++) // bytes[i] = (byte)(Math.random() * 255); return buf.array(); }