List of usage examples for android.graphics Paint Paint
public Paint()
From source file:org.madmatrix.zxing.android.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of * the barcode./*from w w w . j a va 2 s .c o m*/ * * @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. */ 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:com.example.SmartBoard.DrawingView.java
@Override protected void onDraw(Canvas canvas) { drawCanvas.drawPath(drawPath, drawPaint); drawCanvas.drawPath(drawPathRecv, drawPaintSender); if (rectMode) { //draw rectangle drawPaint.setXfermode(null);// w w w. ja v a2 s .co m onDrawRectangle(canvas); } else if (circleMode) { drawPaint.setXfermode(null); onDrawCircle(canvas); } else if (lineMode) { drawPaint.setXfermode(null); onDrawLine(canvas); } else if (textMode) { drawPaint.setXfermode(null); onDrawText(canvas); } else if (dragMode && !dragFinished) { drawPaint.setXfermode(null); onDragDraw(canvas, dragX, dragY); } else if (colorDropperMode) { drawPaint.setXfermode(null); onDrawColorDropper(canvas, dropperX, dropperY); } else if (textSizeMode) { drawPaint.setXfermode(null); } canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); //redraw objects Paint tempPaint = new Paint(); tempPaint.setStyle(Paint.Style.STROKE); for (String key : textObjects.keySet()) { if (key.compareTo("") == 0) { continue; } JSONObject o = textObjects.get(key); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } for (String key : objectDrawables.keySet()) { //hashtable problems no time to explain. But it creates a duplicate of last item I add to the table. //So dont print duplicates which have empty string key values if (key.compareTo("") == 0) { continue; } JSONObject o = objectDrawables.get(key); String objectType = o.optString("type"); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); if (objectType.compareTo("Circle") == 0) { canvas.drawCircle(o.optInt("x"), o.optInt("y"), o.optInt("radius"), tempPaint); } else if (objectType.compareTo("Line") == 0) { canvas.drawLine(o.optInt("startx"), o.optInt("starty"), o.optInt("stopx"), o.optInt("stopy"), tempPaint); } else if (objectType.compareTo("Rectangle") == 0) { canvas.drawRect(Rect.unflattenFromString(o.optString("dimens")), tempPaint); } else if (objectType.compareTo("Text") == 0) { //canvas.drawRect(Rect.unflattenFromString(o.optString("region")), drawPaint); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } } }
From source file:info.papdt.blacklight.support.Utility.java
public static int getFontHeight(Context context, float fontSize) { // Convert Dp To Px float px = context.getResources().getDisplayMetrics().density * fontSize + 0.5f; // Use Paint to get font height Paint p = new Paint(); p.setTextSize(px);/*from w w w .ja v a 2 s .co m*/ FontMetrics fm = p.getFontMetrics(); return (int) Math.ceil(fm.descent - fm.ascent); }
From source file:com.tealeaf.TeaLeaf.java
public Bitmap getBitmapFromView(EditText view) { //Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); //Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); //Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { //has background drawable, then draw it on the canvas bgDrawable.draw(canvas);//from w w w . j a v a 2s . c o m } // draw the view on the canvas view.draw(canvas); Paint p = new Paint(); p.setColor(Color.BLACK); p.setTextSize(24); canvas.drawText("'ello mate", 0, 0, p); //return the bitmap return returnedBitmap; }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawGaugeTitle(Canvas canvas, String Title) { Paint titlePaint = new Paint(); titlePaint.setStyle(Paint.Style.FILL_AND_STROKE); titlePaint.setColor(Color.LTGRAY);//0x9f004d0f titlePaint.setStrokeWidth(1);//0.005f titlePaint.setAntiAlias(true);/*w w w . j a va 2 s . c o m*/ titlePaint.setTextSize(14); titlePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf")); /*Path titlePath = new Path(); titlePath.addArc(new RectF(40, 90, 196, 155), -180.0f, -180.0f); canvas.drawTextOnPath(Title, titlePath, 0.0f,0.0f, titlePaint);*/ canvas.drawText(Title, 60, 160, titlePaint); }
From source file:com.longle1.facedetection.MainActivity.java
@Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.GREEN);/*from w ww .ja v a 2 s . com*/ paint.setTextSize(20); String s = "FacePreview - This side up."; float textWidth = paint.measureText(s); canvas.drawText(s, (getWidth() - textWidth) / 2, 20, paint); if (faces != null) { paint.setStrokeWidth(5); paint.setStyle(Paint.Style.STROKE); float scaleX = (float) getWidth() / grayImage.width(); float scaleY = (float) getHeight() / grayImage.height(); int total = faces.total(); for (int i = 0; i < total; i++) { CvRect r = new CvRect(cvGetSeqElem(faces, i)); int x = r.x(), y = r.y(), w = r.width(), h = r.height(); canvas.drawRect(x * scaleX, y * scaleY, (x + w) * scaleX, (y + h) * scaleY, paint); } } }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawScale(Canvas canvas, Boolean Colors, int Count, int Max) { RectF faceRect = new RectF(); faceRect.set(10, 10, 190, 190);//from w ww.j a va2 s. com Paint scalePaint = new Paint(); scalePaint.setStyle(Paint.Style.STROKE); scalePaint.setColor(getResources().getColor(R.color.WarningGreen)); scalePaint.setStrokeWidth(1); scalePaint.setAntiAlias(true); scalePaint.setTextSize(12); scalePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf")); scalePaint.setTextAlign(Paint.Align.CENTER); float scalePosition = 10; RectF scaleRect = new RectF(); scaleRect.set(faceRect.left + scalePosition, faceRect.top + scalePosition, faceRect.right - scalePosition, faceRect.bottom - scalePosition); if (!Colors) scalePaint.setColor(Color.WHITE); scalePaint.setStrokeWidth(2); canvas.save(Canvas.MATRIX_SAVE_FLAG); for (int i = 0; i < Max; ++i) { if (Colors) { if (i > 20) scalePaint.setColor(getResources().getColor(R.color.WarningYellow)); if (i > 40) scalePaint.setColor(getResources().getColor(R.color.WarningOrange)); if (i > 60) scalePaint.setColor(getResources().getColor(R.color.WarningRed)); } canvas.drawLine(100, 20, 100, 18, scalePaint); int divisor = 5; if (Max > 100) divisor = 25; if (i % divisor == 0) { canvas.drawText(Integer.toString(i), 100, 16, scalePaint); } canvas.rotate((360.0f / Max), 100, 100); } canvas.restore(); }
From source file:ch.ethz.dcg.jukefox.manager.libraryimport.AndroidAlbumCoverFetcherThread.java
private void drawTextOnBitmap(CompleteAlbum album, Bitmap bitmapHigh, int bitmapSize, float textHeight) { Canvas canvas = new Canvas(bitmapHigh); canvas.drawARGB(0, 125, 125, 125);//from ww w. j a va 2s.co m Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setTypeface(Typeface.SERIF); paint.setSubpixelText(true); paint.setTextSize(textHeight); paint.setAntiAlias(true); String artist = album.getArtists().get(0).getName(); String shortenedText = new String(artist); int textLength = artist.length(); if (textLength > 18) { shortenedText = artist.substring(0, 15) + "..."; textLength = 18; } else if (textLength < 8) { while (shortenedText.length() < 8) { shortenedText = " " + shortenedText + " "; } } float pixelLength = paint.measureText(shortenedText); paint.setTextSize(textHeight * (bitmapSize * 2 / 3) / pixelLength); canvas.drawText(shortenedText, bitmapSize / 6, bitmapSize / 3, paint); shortenedText = album.getName(); textLength = album.getName().length(); if (textLength > 18) { shortenedText = album.getName().substring(0, 15) + "..."; textLength = 18; } else if (textLength < 8) { while (shortenedText.length() < 8) { shortenedText = " " + shortenedText + " "; } } paint.setTextSize(bitmapSize / 10f); pixelLength = paint.measureText(shortenedText); textHeight = textHeight * bitmapSize * 2f / 3f / pixelLength; paint.setTextSize(textHeight); canvas.drawText(shortenedText, bitmapSize / 6f, bitmapSize * 2 / 3f + textHeight, paint); }
From source file:net.exclaimindustries.geohashdroid.util.KnownLocation.java
@NonNull private Bitmap buildMarkerBitmap(@NonNull Context c) { // Oh, this is going to be FUN. int dim = c.getResources().getDimensionPixelSize(R.dimen.known_location_marker_canvas_size); float radius = c.getResources().getDimension(R.dimen.known_location_pin_head_radius); Bitmap bitmap = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true);/*from w w w .j a va 2 s .co m*/ KnownLocationPinData pinData = new KnownLocationPinData(c, mLocation); // Draw the pin line first. That goes from the bottom-center up to // wherever the radius and length take us. float topX = Double.valueOf((dim / 2) + (pinData.getLength() * Math.cos(pinData.getAngle()))).floatValue(); float topY = Double.valueOf(dim - (pinData.getLength() * Math.sin(pinData.getAngle()))).floatValue(); paint.setStrokeWidth(c.getResources().getDimension(R.dimen.known_location_stroke)); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLACK); canvas.drawLine(dim / 2, dim, topX, topY, paint); // On the top of that line, fill in a circle. paint.setColor(pinData.getColor()); paint.setStyle(Paint.Style.FILL); canvas.drawCircle(topX, topY, radius, paint); // And outline it. paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(topX, topY, radius, paint); return bitmap; }
From source file:com.cssweb.android.view.KlineMini.java
public void drawQuoteWin(Canvas canvas, JSONObject quoteData, int idx) throws JSONException { Paint mPaint = new Paint(); mPaint.setTextAlign(Paint.Align.LEFT); mPaint.setStyle(Paint.Style.STROKE); mPaint.setTypeface(Typeface.DEFAULT_BOLD); mPaint.setAntiAlias(true);/*from w ww .ja v a2s . c o m*/ mPaint.setColor(GlobalColor.colorKlinePopub); mPaint.setTextSize(sTextSize); canvas.drawText(":", 0, axisLabelHeight, mPaint); canvas.drawText(":", 0, axisLabelHeight * 3, mPaint); canvas.drawText(":", 0, axisLabelHeight * 5, mPaint); canvas.drawText(":", 0, axisLabelHeight * 7, mPaint); canvas.drawText(":", 0, axisLabelHeight * 9, mPaint); canvas.drawText(":", 0, axisLabelHeight * 11, mPaint); mPaint.setTextAlign(Paint.Align.RIGHT); String qt = quoteData.getJSONArray("K").getJSONArray(idx).getString(0); double jrkp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(1); double zg = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(2); double zd = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(3); double sp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4); double preclose; if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) { switch (idx) { case 0: preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(7); break; default: preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(7); break; } if (quoteData.getJSONArray("K").length() == 1) { preclose = quoteData.getJSONArray("K").getJSONArray(0).getDouble(7); } } else { switch (idx) { case 0: preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4); break; default: preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(4); break; } if (quoteData.getJSONArray("K").length() == 1) { preclose = quoteData.getDouble("zrsp");//quoteData.getJSONArray("K").getJSONArray(0).getDouble(4); } } // if(quoteData.getJSONArray("K").length()==1 && quoteData.getJSONObject("todayData")!=null){ // preclose = quoteData.getJSONObject("todayData").getDouble("zrsp"); // } mPaint.setColor(getcolor(jrkp, preclose)); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), klineX, axisLabelHeight * 2, mPaint); mPaint.setColor(getcolor(zg, preclose)); canvas.drawText(Utils.dataFormation(zg, stockdigit), klineX, axisLabelHeight * 4, mPaint); mPaint.setColor(getcolor(zd, preclose)); canvas.drawText(Utils.dataFormation(zd, stockdigit), klineX, axisLabelHeight * 6, mPaint); mPaint.setColor(getcolor(sp, preclose)); canvas.drawText(Utils.dataFormation(sp, stockdigit), klineX, axisLabelHeight * 8, mPaint); double zhangdie = sp - preclose; if (zhangdie > 0) mPaint.setColor(GlobalColor.colorpriceUp); else if (zhangdie < 0) mPaint.setColor(GlobalColor.colorPriceDown); else mPaint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.dataFormation(zhangdie, 1), klineX, axisLabelHeight * 10, mPaint); if (quoteData.getString("period").equals("min5") || quoteData.getString("period").equals("min15") || quoteData.getString("period").equals("min30") || quoteData.getString("period").equals("min60")) { qt = qt.substring(4, 6) + '/' + qt.substring(6, 8) + ' ' + qt.substring(8); } else { qt = qt.substring(2, 4) + qt.substring(4, 6) + qt.substring(6, 8); } mPaint.setColor(GlobalColor.colorLabelName); canvas.drawText(qt, klineX, axisLabelHeight * 12, mPaint); }