List of usage examples for android.graphics Paint Paint
public Paint()
From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode. * * @param barcode A bitmap of the captured image. * @param scaleFactor amount by which thumbnail was scaled * @param rawResult The decoded results which contains the points to draw. *//*from w w w . j ava2 s . co m*/ private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0) { Canvas canvas = new Canvas(barcode); Paint paint = new Paint(); paint.setColor(getResources().getColor(R.color.result_points)); if (points.length == 2) { paint.setStrokeWidth(4.0f); drawLine(canvas, paint, points[0], points[1], scaleFactor); } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) { // Hacky special case -- draw two lines, for the barcode and metadata drawLine(canvas, paint, points[0], points[1], scaleFactor); drawLine(canvas, paint, points[2], points[3], scaleFactor); } else { paint.setStrokeWidth(10.0f); for (ResultPoint point : points) { if (point != null) { canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint); } } } } }
From source file:de.madvertise.android.sdk.MadView.java
/** * Draw the ad background for a text banner * /* ww w. ja v a 2 s .c o m*/ * @param canvas * @param rectangle * @param backgroundColor * @param textColor */ private void drawTextBannerBackground(Canvas canvas, Rect rectangle, int backgroundColor, int shineColor) { Paint paint = new Paint(); paint.setColor(backgroundColor); paint.setAntiAlias(true); canvas.drawRect(rectangle, paint); int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor), Color.blue(shineColor)); int[] gradientColors = { upperColor, shineColor }; GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, gradientColors); int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top; gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop); gradientDrawable.draw(canvas); Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom); Paint shadowPaint = new Paint(); shadowPaint.setColor(shineColor); canvas.drawRect(shadowRect, shadowPaint); }
From source file:com.bamobile.fdtks.util.Tools.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output;//from w w w. ja v a2 s. c om if (bitmap.getWidth() > bitmap.getHeight()) { output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888); } else { output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), 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()); float r = 0; if (bitmap.getWidth() > bitmap.getHeight()) { r = bitmap.getHeight() / 2; } else { r = bitmap.getWidth() / 2; } paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(r, r, r, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java
public static Bitmap resizeAndRoundCorners(Bitmap bitmap, int maxSize) { boolean isLandscape = bitmap.getWidth() > bitmap.getHeight(); int newWidth, newHeight; if (isLandscape) { newWidth = maxSize;/* w ww . ja va 2s .c o m*/ newHeight = Math.round(((float) newWidth / bitmap.getWidth()) * bitmap.getHeight()); } else { newHeight = maxSize; newWidth = Math.round(((float) newHeight / bitmap.getHeight()) * bitmap.getWidth()); } Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); if (resizedBitmap != bitmap) bitmap.recycle(); Bitmap roundedProfile = Bitmap.createBitmap(resizedBitmap.getWidth(), resizedBitmap.getHeight(), Config.ARGB_8888); Canvas roundedCanvas = new Canvas(roundedProfile); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, roundedProfile.getWidth(), roundedProfile.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = 7.0f; paint.setAntiAlias(true); roundedCanvas.drawARGB(0, 0, 0, 0); paint.setColor(color); roundedCanvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); roundedCanvas.drawBitmap(resizedBitmap, rect, rect, paint); return roundedProfile; }
From source file:com.bamobile.fdtks.util.Tools.java
public static Bitmap getCircularBitmapWithWhiteBorder(Bitmap bitmap, int borderWidth) { if (bitmap == null || bitmap.isRecycled()) { return null; }//w w w. ja va2 s. c o m final int width = bitmap.getWidth() + borderWidth; final int height = bitmap.getHeight() + borderWidth; Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader); Canvas canvas = new Canvas(canvasBitmap); float radius = width > height ? ((float) height) / 2f : ((float) width) / 2f; canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setShader(null); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLUE); paint.setStrokeWidth(borderWidth); canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2, paint); return canvasBitmap; }
From source file:com.example.hudpassthrough.BluetoothChat.java
private Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();/* w ww. ja v a 2 s . co m*/ width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }
From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of * the barcode./*w w w . ja v a2 s. c om*/ * * @param barcode * A bitmap of the captured image. * @param rawResult * The decoded results which contains the points to draw. */ private void drawResultPoints(Bitmap barcode, Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0) { Canvas canvas = new Canvas(barcode); Paint paint = new Paint(); paint.setColor(getResources().getColor(R.color.result_points)); if (points.length == 2) { paint.setStrokeWidth(4.0f); drawLine(canvas, paint, points[0], points[1]); } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) { // Hacky special case -- draw two lines, for the barcode and // metadata drawLine(canvas, paint, points[0], points[1]); drawLine(canvas, paint, points[2], points[3]); } else { paint.setStrokeWidth(10.0f); for (ResultPoint point : points) { canvas.drawPoint(point.getX(), point.getY(), paint); } } } }
From source file:com.c4mprod.utils.ImageManager.java
public static Bitmap getRoundedCornerBitmap(Bitmap 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 = 20; paint.setAntiAlias(true);//from ww w.ja v a2 s.c om 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); if (output != bitmap) { bitmap.recycle(); } return output; }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { 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 = pixels; paint.setAntiAlias(true);/*from w w w . j a v a 2s . co m*/ 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; }