Example usage for android.graphics Paint setColor

List of usage examples for android.graphics Paint setColor

Introduction

In this page you can find the example usage for android.graphics Paint setColor.

Prototype

public void setColor(@ColorInt int color) 

Source Link

Document

Set the paint's color.

Usage

From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java

/**
 * Sets the downloaded attached image./*from   w  ww . ja  v a 2 s  .  c o  m*/
 *
 * @param fileName picture file path
 */
public static Bitmap publishPicture(String fileName) {
    Bitmap bitmap = null;
    try {

        if (!TextUtils.isEmpty(fileName)) {
            try {
                BitmapFactory.Options opts = new BitmapFactory.Options();
                opts.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(fileName, opts);

                //Find the correct scale value. It should be the power of 2.
                int width = opts.outWidth, height = opts.outHeight;
                int scale = 1;
                while (true) {
                    if (width / 2 <= 150 || height / 2 <= 150) {
                        break;
                    }
                    width /= 2;
                    height /= 2;
                    scale *= 2;
                }
                BitmapFactory.Options opt = new BitmapFactory.Options();
                opt.inSampleSize = scale;

                bitmap = BitmapFactory.decodeFile(fileName, opt);
                int size = 0;
                if (bitmap.getHeight() > bitmap.getWidth()) {
                    size = bitmap.getWidth();
                } else {
                    size = bitmap.getHeight();
                }
                Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
                Canvas canvas = new Canvas(output);

                final int color = 0xff424242;
                final Paint paint = new Paint();
                final Rect rect = new Rect(0, 0, size, size);
                final RectF rectF = new RectF(rect);
                final float roundPx = 0;

                paint.setAntiAlias(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);

                bitmap.recycle();

                return output;
            } catch (Exception e) {
                Log.w("", "");
            }
        }
    } catch (Exception ex) {

    }

    return null;
}

From source file:de.chrthms.chess.board.markers.MenaceFieldView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint();
    paint.setColor(ContextCompat.getColor(getContext(), R.color.basicFieldIvalidColor));

    canvas.drawRect(getLeft(), getTop(), getRight(), getBottom(), 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  .j  ava  2s .  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:de.chrthms.chess.board.markers.SourceFieldView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint();
    paint.setColor(ContextCompat.getColor(getContext(), R.color.basicFieldPossibleColor));
    paint.setStrokeWidth((getWidth() * 1f) / 100 * STROKE_WIDTH);

    float[] points = { getLeft(), getTop(), getRight(), getTop(), getRight(), getTop(), getRight(), getBottom(),
            getRight(), getBottom(), getLeft(), getBottom(), getLeft(), getBottom(), getLeft(), getTop() };

    canvas.drawLines(points, paint);//  w w  w .java2s .c  om

}

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 w w.j av a2  s .  c om
 *         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: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;/*from  w  w w. ja  v a 2  s.  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.nextgis.maplib.display.SimpleLineStyle.java

@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    GeoLineString line = (GeoLineString) geoGeometry;
    Paint lnPaint = new Paint();
    lnPaint.setColor(mColor);
    lnPaint.setStrokeWidth((float) (mWidth / display.getScale()));
    lnPaint.setStrokeCap(Paint.Cap.ROUND);
    lnPaint.setAntiAlias(true);//from  ww  w.j av a 2 s . c  o m

    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);
}

From source file:de.chrthms.chess.board.markers.PossibleFieldView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint();

    paint.setColor(ContextCompat.getColor(getContext(), R.color.basicFieldPossibleColor));
    paint.setStrokeWidth((getWidth() * 1f) / 100 * STROKE_WIDTH);

    // transform int (width) to float!
    float space = (getWidth() * 1f) / 100 * MARKER_SPACE;
    float size = (getWidth() * 1f) / 100 * MARKER_SIZE;

    Log.i("MARKER POINTS", "space = " + space + " size = " + size + " width = " + getWidth());

    float[] points = { getLeft() + space, getTop() + space, getLeft() + space + size, getTop() + space,
            getLeft() + space, getTop() + space, getLeft() + space, getTop() + space + size,

            getRight() - space - size, getTop() + space, getRight() - space, getTop() + space,
            getRight() - space, getTop() + space, getRight() - space, getTop() + space + size,

            getLeft() + space, getBottom() - space, getLeft() + space + size, getBottom() - space,
            getLeft() + space, getBottom() - space, getLeft() + space, getBottom() - space - size,

            getRight() - space - size, getBottom() - space, getRight() - space, getBottom() - space,
            getRight() - space, getBottom() - space, getRight() - space, getBottom() - space - size,

    };//from www . j  av a 2  s .c  o  m

    Log.i("MARKER POINTS", "points array = " + Arrays.toString(points));

    canvas.drawLines(points, paint);

}

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 www  . j  a va2 s  .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;
}

From source file:com.busdrone.android.ui.VehicleMarkerRenderer.java

private Bitmap render(int color, String text) {
    TextPaint textPaint = new TextPaint();
    textPaint.setColor(Color.WHITE);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setAntiAlias(true);/*from  ww w  .ja v a 2  s.  com*/
    textPaint.setTextSize(mTextSize);

    Rect textBounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), textBounds);

    int width = mPadding + textBounds.width() + mPadding;
    int height = mPadding + textBounds.height() + mPadding;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(color);
    canvas.drawRoundRect(new RectF(0, 0, width, height), mCornerRadius, mCornerRadius, paint);

    canvas.drawText(text, (width / 2f) - (textBounds.width() / 2f), (height / 2f) + (textBounds.height() / 2f),
            textPaint);

    return bitmap;
}