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:Main.java

static void mutatePaint(Paint paint, int color, float strokeWidth, Paint.Style style) {
    paint.setColor(color);
    paint.setStrokeWidth(strokeWidth);/*from   ww w .ja v  a  2s  .  com*/
    paint.setStyle(style);
}

From source file:Main.java

public static int filter(final ColorFilter filter, final int color) {
    final Paint paint = new Paint();
    paint.setColor(color);
    paint.setColorFilter(filter);//from  w w  w.  j a  v  a  2s .co  m
    final Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    canvas.drawPaint(paint);
    return bitmap.getPixel(0, 0);
}

From source file:Main.java

public static Bitmap forceConfig565(Bitmap original) {
    Bitmap convertedBitmap = original;//from w w w  .  j a  va2s.c om
    if (original.getConfig() != Bitmap.Config.RGB_565) {
        convertedBitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(convertedBitmap);
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        canvas.drawBitmap(original, 0, 0, paint);

        if (convertedBitmap != original) {
            original.recycle();
        }
    }

    return convertedBitmap;
}

From source file:Main.java

public static Bitmap drawBackground(int cellSize, int height, int widht) {

    Bitmap bitmap = Bitmap.createBitmap(widht, height, Config.ARGB_8888);
    Canvas cv = new Canvas(bitmap);

    Paint background = new Paint();
    background.setColor(BACKGROUND_COLOR);
    cv.drawRect(0, 0, widht, height, background);
    background.setAntiAlias(true);/*from   w w w.  j av a  2s. c  o m*/

    background.setColor(LINE_COLOR);

    for (int i = 0; i < widht / cellSize; i++) {
        cv.drawLine(cellSize * i, 0, cellSize * i, height, background);
    }

    for (int i = 0; i < height / cellSize; i++) {
        cv.drawLine(0, cellSize * i, widht, cellSize * i, background);
    }
    return bitmap;
}

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.dragdrop.BitmapUtils.java

/**
 * Returns a bitmap showing a screenshot of the view passed in.
 *//*  w w w.  j  av  a 2s.co  m*/
@NonNull
static Bitmap getBitmapFromView(@NonNull final View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint p = new Paint();
    p.setColor(ContextCompat.getColor(v.getContext(), R.color.colorAccent));
    p.setAlpha(50);
    //v.setBackgroundColor(ContextCompat.getColor(v.getContext(), android.R.color.transparent));
    v.draw(canvas);
    //canvas.drawCircle((float)(v.getWidth() / 2), (float)(v.getHeight() / 2), 10, p);
    canvas.drawRect(new Rect(0, 0, v.getWidth(), v.getHeight()), p);
    return bitmap;
}

From source file:Main.java

/**
 * Draw the face rect in the Image//from ww w  .j a v  a 2  s.c o m
 * @param canvas
 * @param face
 * @param width
 * @param height
 * @param frontCamera
 */
static public void drawFaceRect(Canvas canvas, Rect rect, int width, int height, boolean frontCamera) {

    if (canvas == null)
        return;

    Paint paint = new Paint();
    paint.setColor(Color.rgb(57, 138, 243));
    int len = (rect.bottom - rect.top) / 8;
    if (len / 8 >= 2)
        paint.setStrokeWidth(len / 8);
    else
        paint.setStrokeWidth(2);

    if (frontCamera) {
        int left = rect.left;
        rect.left = width - rect.right;
        rect.right = width - left;
    }

    paint.setStyle(Style.STROKE);
    canvas.drawRect(rect, paint);
}

From source file:Main.java

public static void drawKnots(Canvas canvas, List<PointF> knots, int color) {
    Log.d("GammaGraph", "function drawKnots");
    Paint paint = new Paint();
    paint.setAntiAlias(true);//  w w  w  . jav  a2 s .  co m
    paint.setColor(color);
    paint.setStrokeWidth(7);
    for (PointF knot : knots) {
        canvas.drawPoint(knot.x, knot.y, paint);
    }
}

From source file:Main.java

/**
 * Creates the Paint object for drawing the crop window border.
 * //from ww w . j a va2  s  .com
 * @param context the Context
 * @return new Paint object
 */
public static Paint newBorderPaint(Context context) {

    // Set the line thickness for the crop window border.
    final float lineThicknessPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            DEFAULT_LINE_THICKNESS_DP, context.getResources().getDisplayMetrics());

    final Paint borderPaint = new Paint();
    borderPaint.setColor(Color.parseColor(SEMI_TRANSPARENT));
    borderPaint.setStrokeWidth(lineThicknessPx);
    borderPaint.setStyle(Paint.Style.STROKE);

    return borderPaint;
}

From source file:Main.java

/**
 * Creates the Paint object for drawing the corners of the border
 * /*ww  w  . j ava 2 s.c  o  m*/
 * @param context the Context
 * @return the new Paint object
 */
public static Paint newCornerPaint(Context context) {

    // Set the line thickness for the crop window border.
    final float lineThicknessPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            DEFAULT_CORNER_THICKNESS_DP, context.getResources().getDisplayMetrics());

    final Paint cornerPaint = new Paint();
    cornerPaint.setColor(DEFAULT_CORNER_COLOR);
    cornerPaint.setStrokeWidth(lineThicknessPx);
    cornerPaint.setStyle(Paint.Style.STROKE);

    return cornerPaint;
}

From source file:Main.java

public static Bitmap setReflection(Bitmap bitmap, int distance, float ratio) {
    final int reflectionGap = distance;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);/*from ww  w. j av  a2  s.  co  m*/
    Bitmap reflectionBitmap = Bitmap.createBitmap(bitmap, 0, height / 2, width, (int) (height * ratio), matrix,
            false);
    Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height + (int) (height * ratio) + reflectionGap),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(withReflectionBitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint defaultPaint = new Paint();
    defaultPaint.setColor(Color.TRANSPARENT);
    canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
    canvas.drawBitmap(reflectionBitmap, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, withReflectionBitmap.getHeight(),
            0x70ffffff, 0x00ffffff, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(), paint);
    return withReflectionBitmap;
}