List of usage examples for android.graphics Paint setStrokeWidth
public void setStrokeWidth(float width)
From source file:ee.ioc.phon.android.speak.Utils.java
/** * <p>Returns a bitmap that visualizes the given waveform (byte array), * i.e. a sequence of 16-bit integers.</p> * * TODO: show to high/low points in other color * TODO: show end pause data with another color *//*from w ww. j av a2 s . c om*/ public static Bitmap drawWaveform(byte[] waveBuffer, int w, int h, int start, int end) { final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); final Canvas c = new Canvas(b); final Paint paint = new Paint(); paint.setColor(0xFFFFFFFF); // 0xRRGGBBAA paint.setAntiAlias(true); paint.setStrokeWidth(0); final Paint redPaint = new Paint(); redPaint.setColor(0xFF000080); redPaint.setAntiAlias(true); redPaint.setStrokeWidth(0); final ShortBuffer buf = ByteBuffer.wrap(waveBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); buf.position(0); final int numSamples = waveBuffer.length / 2; //final int delay = (SAMPLING_RATE * 100 / 1000); final int delay = 0; int endIndex = end / 2 + delay; if (end == 0 || endIndex >= numSamples) { endIndex = numSamples; } int index = start / 2 - delay; if (index < 0) { index = 0; } final int size = endIndex - index; int numSamplePerPixel = 32; int delta = size / (numSamplePerPixel * w); if (delta == 0) { numSamplePerPixel = size / w; delta = 1; } final float scale = 3.5f / 65536.0f; // do one less column to make sure we won't read past // the buffer. try { for (int i = 0; i < w - 1; i++) { final float x = i; for (int j = 0; j < numSamplePerPixel; j++) { final short s = buf.get(index); final float y = (h / 2) - (s * h * scale); if (s > Short.MAX_VALUE - 10 || s < Short.MIN_VALUE + 10) { // TODO: make it work c.drawPoint(x, y, redPaint); } else { c.drawPoint(x, y, paint); } index += delta; } } } catch (IndexOutOfBoundsException e) { // this can happen, but we don't care } return b; }
From source file:com.github.barcodeeye.scan.CaptureActivity.java
/** * Superimpose a line for 1D or dots for 2D to highlight the key features of * the barcode./*from w w w .j ava 2 s. com*/ * * @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 static void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult, int color) { ResultPoint[] points = rawResult.getResultPoints(); if (points != null && points.length > 0) { Canvas canvas = new Canvas(barcode); Paint paint = new Paint(); paint.setColor(color); 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:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java
private static void drawPath(GoogleMap map, List<LatLng> points, int color) { // int x1 = -1, y1 = -1, x2 = -1, y2 = -1; Paint paint = new Paint(); paint.setColor(color);/* w w w . java 2 s .c o m*/ paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStrokeWidth(6); PolylineOptions po = new PolylineOptions().addAll(points).width(6).color(color); Polyline pl = map.addPolyline(po); pl.setVisible(true); }
From source file:Main.java
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius, int border, int color) { Bitmap scaledBitmap;// w ww . ja v a 2 s . c om if (bmp.getWidth() != radius || bmp.getHeight() != radius) { scaledBitmap = ThumbnailUtils.extractThumbnail(bmp, radius - 2, radius - 2); } else { scaledBitmap = bmp; } Bitmap output = Bitmap.createBitmap(scaledBitmap.getWidth(), scaledBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2, scaledBitmap.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); final Rect rect = new Rect(0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight()); canvas.drawBitmap(scaledBitmap, rect, rect, paint); if (border > 0) { paint.setStrokeWidth(border); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2, scaledBitmap.getWidth() / 2, paint); } return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int color, int cornerDips, int borderDips, Context context, boolean recycleOrig) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int borderSizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) borderDips, context.getResources().getDisplayMetrics()); final int cornerSizePx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) cornerDips, context.getResources().getDisplayMetrics()); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); // prepare canvas for transfer paint.setAntiAlias(true);/*from w ww . j a v a 2s .co m*/ paint.setColor(0xFFFFFFFF); paint.setStyle(Paint.Style.FILL); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, cornerSizePx, cornerSizePx, paint); // draw bitmap paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); // draw border paint.setColor(color); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth((float) borderSizePx); canvas.drawRoundRect(rectF, cornerSizePx, cornerSizePx, paint); if (recycleOrig && bitmap != null && !bitmap.isRecycled()) bitmap.recycle(); return output; }
From source file:Main.java
/** * Create circle image.// w w w. j ava 2 s. c om * * @param bitmap Bitmap to be cropped * @param resColor Resource color * @param strokeWidth Thickness of stroke * @return Returns the circle image with border */ public static Bitmap getCircleImage(Bitmap bitmap, int resColor, int strokeWidth) { // create Bitmap to draw Bitmap mBitmap = Bitmap.createBitmap(bitmap.getWidth() + 8, bitmap.getHeight() + 8, Bitmap.Config.ARGB_8888); // create Rect to hold image final Rect mRec = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); // create Canvas Canvas mCanvas = new Canvas(mBitmap); mCanvas.drawARGB(0, 0, 0, 0); // create Paint final Paint mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); mPaint.setAntiAlias(true); // get the half size of the image int mHalfWidth = bitmap.getWidth() / 2; int mHalfHeight = bitmap.getHeight() / 2; // draw circle mCanvas.drawCircle((mHalfWidth + 4), (mHalfHeight + 4), Math.min(mHalfWidth, mHalfHeight), mPaint); // unknown mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // draw the image mCanvas.drawBitmap(bitmap, mRec, mRec, mPaint); // set border mode mPaint.setXfermode(null); // set stroke mPaint.setStyle(Paint.Style.STROKE); // set stroke color mPaint.setColor(resColor); // set stroke width mPaint.setStrokeWidth(strokeWidth); // draw stroke mCanvas.drawCircle((mHalfWidth + 4), (mHalfHeight + 4), Math.min(mHalfWidth, mHalfHeight), mPaint); // return the circle image return mBitmap; }
From source file:Main.java
/** * Gets the rounded corner bitmap.//from w ww .ja v a 2s . c o m * * @param bitmap * the bitmap * @return the rounded corner bitmap */ public static Bitmap getRoundedCornerBitmap(Context context, Bitmap bitmap, Boolean create_circle) { DisplayMetrics mMetrics = context.getResources().getDisplayMetrics(); float mScaleFactor = mMetrics.density; Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = Color.BLACK; final Paint paint = new Paint(); int width = bitmap.getWidth(); int height = (bitmap.getHeight() > width) ? width : bitmap.getHeight(); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); final float roundPx = (create_circle) ? (bitmap.getWidth() > 360) ? bitmap.getWidth() : 360 : 2; paint.setAntiAlias(true); paint.setColor(color); paint.setStyle(Paint.Style.FILL); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); // draw border paint.setColor(Color.parseColor("#cccccc")); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(0.5F * mScaleFactor); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); return output; }
From source file:de.mrapp.android.util.BitmapUtil.java
/** * Clips the long edge of a bitmap, if its width and height are not equal, in order to transform * it into a square. Additionally, the bitmap is resized to a specific size and a border will be * added./*w ww . j a va 2 s . co m*/ * * @param bitmap * The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The * bitmap may not be null * @param size * The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The * size must be at least 1 * @param borderWidth * The width of the border as an {@link Integer} value in pixels. The width must be at * least 0 * @param borderColor * The color of the border as an {@link Integer} value * @return The clipped bitmap as an instance of the class {@link Bitmap} */ public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int size, final int borderWidth, @ColorInt final int borderColor) { ensureAtLeast(borderWidth, 0, "The border width must be at least 0"); Bitmap clippedBitmap = clipSquare(bitmap, size); Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); float offset = borderWidth / 2.0f; Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight()); RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset); canvas.drawBitmap(clippedBitmap, src, dst, null); if (borderWidth > 0 && Color.alpha(borderColor) != 0) { Paint paint = new Paint(); paint.setFilterBitmap(false); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); paint.setColor(borderColor); offset = borderWidth / 2.0f; RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset); canvas.drawRect(bounds, paint); } return result; }
From source file:de.mrapp.android.util.BitmapUtil.java
/** * Clips the corners of a bitmap in order to transform it into a round shape. Additionally, the * bitmap is resized to a specific size and a border will be added. Bitmaps, whose width and * height are not equal, will be clipped to a square beforehand. * * @param bitmap/* w ww. j a v a 2s. c o m*/ * The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The * bitmap may not be null * @param size * The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The * size must be at least 1 * @param borderWidth * The width of the border as an {@link Integer} value in pixels. The width must be at * least 0 * @param borderColor * The color of the border as an {@link Integer} value * @return The clipped bitmap as an instance of the class {@link Bitmap} */ public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size, final int borderWidth, @ColorInt final int borderColor) { ensureAtLeast(borderWidth, 0, "The border width must be at least 0"); Bitmap clippedBitmap = clipCircle(bitmap, size); Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); float offset = borderWidth / 2.0f; Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight()); RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset); canvas.drawBitmap(clippedBitmap, src, dst, null); if (borderWidth > 0 && Color.alpha(borderColor) != 0) { Paint paint = new Paint(); paint.setFilterBitmap(false); paint.setAntiAlias(true); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); paint.setColor(borderColor); offset = borderWidth / 2.0f; RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset); canvas.drawArc(bounds, 0, COMPLETE_ARC_ANGLE, false, paint); } return result; }
From source file:com.nextgis.maplib.display.SimpleLineStyle.java
@Override public void onDraw(GeoGeometry geoGeometry, GISDisplay display) { GeoLineString line = (GeoLineString) geoGeometry; Paint lnPaint = new Paint(); lnPaint.setColor(mColor);/*ww w . j a va 2 s .co m*/ lnPaint.setStrokeWidth((float) (mWidth / display.getScale())); lnPaint.setStrokeCap(Paint.Cap.ROUND); lnPaint.setAntiAlias(true); List<GeoPoint> points = line.getPoints(); float[] pts = new float[points.size() * 2]; int counter = 0; for (GeoPoint pt : points) { pts[counter++] = (float) pt.getX(); pts[counter++] = (float) pt.getY(); } display.drawLines(pts, lnPaint); }