List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:id.satusatudua.sigap.ui.fragment.GuardingLocationFragment.java
private Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; 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);/*from w w w. j ava2 s . co m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
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. j a va 2 s.c om 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.bamobile.fdtks.util.Tools.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output;/* w ww .j a v a 2 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:piuk.blockchain.android.ui.zxing.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 rawResult The decoded results which contains the points to draw. *//*from ww w.j a v a 2s.co m*/ 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(ContextCompat.getColor(this, R.color.primary_blue_accent)); 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:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
@SuppressWarnings("unused") private Bitmap RenderLineGraph() { Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888); int width = emptyBmap.getWidth(); int height = emptyBmap.getHeight(); Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(charty); final int color = 0xff0B0B61; final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); //if(warningEvents > ) canvas.drawText("100", 0, 10, paint); //y//from w ww . j av a 2 s .c o m canvas.drawLine(25, 0, 25, 289, paint); //x canvas.drawLine(25, 149, 289, 149, paint); int CritArray[] = { 5, 4, 6, 10, 10, 6, 4, 4 }; int curX = 25; int divisor = 148 / 10; paint.setColor(Color.RED); int curY = 148 - (CritArray[0] * divisor); for (int a : CritArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } int ErrArray[] = { 1, 2, 2, 2, 4, 2, 1, 0 }; curX = 25; paint.setColor(Color.rgb(255, 102, 0)); curY = 148 - (ErrArray[0] * divisor); for (int a : ErrArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } int WarnArray[] = { 0, 2, 4, 8, 10, 4, 2, 2 }; curX = 25; paint.setColor(Color.YELLOW); curY = 148 - (WarnArray[0] * divisor); Path myPath = new Path(); for (int a : WarnArray) { canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint); curX += 32; curY = 148 - (a * divisor); } ByteArrayOutputStream out = new ByteArrayOutputStream(); charty.compress(CompressFormat.PNG, 50, out); return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()); }
From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
private Bitmap RenderBarGraph(int CritCount, int ErrCount, int WarnCount) { //Log.i("Counts", Integer.toString(CritCount) + " / " + Integer.toString(ErrCount) + " / " + Integer.toString(WarnCount)); Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888); int width = emptyBmap.getWidth(); int height = emptyBmap.getHeight(); Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(charty); //final int color = 0xff0B0B61; final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); //y/* w ww. j a v a 2 s .co m*/ canvas.drawLine(25, 0, 25, 289, paint); //x canvas.drawLine(25, 149, 289, 149, paint); paint.setAntiAlias(true); int Max = 0; if (CritCount > ErrCount && CritCount > WarnCount) Max = CritCount; else if (ErrCount > CritCount && ErrCount > WarnCount) Max = ErrCount; else if (WarnCount > CritCount && WarnCount > ErrCount) Max = WarnCount; else Max = CritCount; if (Max > 0) canvas.drawText(Integer.toString(Max), 0, 10, paint); if (Max > 1) canvas.drawText(Integer.toString(Max / 2), 0, 75, paint); canvas.drawText("0", 0, 148, paint); double divisor = 148 / (double) Max; paint.setAlpha(128); Rect rect = new Rect(32, (int) (148 - (divisor * CritCount)), 64, 148); paint.setColor(Color.argb(200, 208, 0, 0)); //red if (CritCount > 0) canvas.drawRect(new RectF(rect), paint); rect = new Rect(128, (int) (148 - (divisor * ErrCount)), 160, 148); paint.setColor(Color.argb(200, 255, 102, 0));//orange if (ErrCount > 0) canvas.drawRect(new RectF(rect), paint); rect = new Rect(224, (int) (148 - (divisor * WarnCount)), 256, 148); paint.setColor(Color.argb(200, 255, 224, 57)); //yellow if (WarnCount > 0) canvas.drawRect(new RectF(rect), paint); //Return ByteArrayOutputStream out = new ByteArrayOutputStream(); charty.compress(CompressFormat.PNG, 50, out); return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewWithMiniKeyboard.java
@Override protected void onBufferDraw(Canvas canvas, Paint paint) { super.onBufferDraw(canvas, paint); // Overlay a dark rectangle to dim the keyboard if (mMiniKeyboardPopup.isShowing()) { paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24); canvas.drawRect(0, 0, getWidth(), getHeight(), paint); }//w ww .j a v a2s .c om }
From source file:com.huahcoding.metrojam.BackTrackActivity.java
/** * This is where we can add markers or lines, add listeners or move the camera. In this case, we * just add a marker near Africa.// www .j a v a 2 s . c o m * <p> * This should only be called once and when we are sure that {@link #mMap} is not null. */ private void setUpMap() { mMap.getUiSettings().setZoomControlsEnabled(false); // Show Lima mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chileLatLng, 15)); mMap.setOnMapLongClickListener(this); mMap.setMyLocationEnabled(true); mMap.setTrafficEnabled(true); // Instantiates a new Polyline object and adds points to define a rectangle PolylineOptions rectOptions = new PolylineOptions(); double[] route = RouteTestData.getChilePoints3(); for (int i = 0; i < route.length - 1; i += 2) { LatLng ll = new LatLng(route[i], route[i + 1]); if (i > 1) { double lat = (route[i] + route[i - 2]) / 2.0; double lng = (route[i + 1] + route[i + 1 - 2]) / 2.0; double dist = distance(route[i], route[i + 1], route[i - 2], route[i + 1 - 2]); String pretty = getPrettyDistance(dist); LatLng ll2 = new LatLng(lat, lng); String strText = pretty; Rect boundsText = new Rect(); Paint textPaint = new Paint(); textPaint.setTextSize(18); textPaint.getTextBounds(strText, 0, strText.length(), boundsText); textPaint.setColor(Color.RED); Bitmap.Config conf = Bitmap.Config.ARGB_8888; Bitmap bmpText = Bitmap.createBitmap(boundsText.width() * 3, boundsText.height(), conf); Canvas canvasText = new Canvas(bmpText); canvasText.drawText(strText, canvasText.getWidth() / 2, canvasText.getHeight(), textPaint); MarkerOptions markerOptions = new MarkerOptions().position(ll2) .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1); mMap.addMarker(markerOptions); } rectOptions.add(ll); } // rectOptions. // Get back the mutable Polyline mMap.addPolyline(rectOptions); }
From source file:co.jlabs.cersei_retailer.zxingfragmentlib.BarCodeScannerFragment.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 ww. j a v a2s.c om private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0 && barcode != null) { 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) { canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint); } } if (isPortrait()) { Log.d(TAG, "rotating results canvas"); canvas.rotate(90); } } }
From source file:com.android.gallery3d.data.UriImage.java
public Bitmap drawTextToBitmap(Context gContext, String gText, Bitmap bitmap) { 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 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 - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (25 * scale)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.setTextAlign(Align.CENTER); paint.getTextBounds(gText, 0, gText.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 2; int y = (bitmap.getHeight() + bounds.height()) / 2; canvas.drawText(gText, x * scale, y * scale, paint); return bitmap; }