Example usage for android.graphics Canvas drawPaint

List of usage examples for android.graphics Canvas drawPaint

Introduction

In this page you can find the example usage for android.graphics Canvas drawPaint.

Prototype

public void drawPaint(@NonNull Paint paint) 

Source Link

Document

Fill the entire canvas' bitmap (restricted to the current clip) with the specified paint.

Usage

From source file:Main.java

public static int filter(final ColorFilter filter, final int color) {
    final Paint paint = new Paint();
    paint.setColor(color);//from  www . ja va 2 s .c o  m
    paint.setColorFilter(filter);
    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 getDummyBitmap(int targetWidth, int targetHeight, int color) {
    Bitmap bitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);/* w w  w.  j av  a  2  s  . c o  m*/
    paint.setColor(color);
    canvas.drawPaint(paint);
    return bitmap;
}

From source file:Main.java

public static final Bitmap complementedBitmapByAlpha(Bitmap bitmap) {
    if (null == bitmap) {
        return null;
    }//  w w w  . j a  v  a  2  s  . com

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width == height) {
        return bitmap;
    }

    int len = width > height ? width : height;
    Bitmap output = Bitmap.createBitmap(len, len, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setAlpha(0);
    canvas.drawPaint(paint);

    if (width > height) {
        int devide = (width - height) / 2;
        canvas.drawBitmap(bitmap, 0, devide, paint_comm);
    } else {
        int devide = (height - width) / 2;
        canvas.drawBitmap(bitmap, devide, 0, paint_comm);
    }
    return output;
}

From source file:Main.java

public static void cleanCanvas(Canvas mCanvas) {
    if (mCanvas != null) {
        Paint paint = new Paint();
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        mCanvas.drawPaint(paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
        mCanvas = null;/* www  . ja  v a 2  s  . c o m*/
    }
}

From source file:Main.java

public static final Bitmap complementedBitmapByColor(Bitmap bitmap, int color) {
    if (null == bitmap) {
        return null;
    }// w w w  . j a  va 2s. c o m

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width == height) {
        return bitmap;
    }

    int len = width > height ? width : height;
    Bitmap output = Bitmap.createBitmap(len, len, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // paint.setAlpha(0);
    paint.setColor(color);
    canvas.drawPaint(paint);

    if (width > height) {
        int devide = (width - height) / 2;
        canvas.drawBitmap(bitmap, 0, devide, paint_comm);
    } else {
        int devide = (height - width) / 2;
        canvas.drawBitmap(bitmap, devide, 0, paint_comm);
    }
    return output;
}

From source file:Main.java

public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX, float spotY,
        Paint p, Paint shadowPaint) {
    float sx = cropBounds.width() * spotX;
    float sy = cropBounds.height() * spotY;
    float cx = cropBounds.centerX();
    float cy = cropBounds.centerY();
    RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    float temp = sx;
    sx = sy;/*from w w w . j av  a 2  s .  c  o m*/
    sy = temp;
    RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    canvas.save();
    canvas.clipRect(cropBounds);
    canvas.clipRect(r1, Region.Op.DIFFERENCE);
    canvas.clipRect(r2, Region.Op.DIFFERENCE);
    canvas.drawPaint(shadowPaint);
    canvas.restore();
    Path path = new Path();
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.right, r1.top);
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.left, r1.bottom);
    path.moveTo(r1.left, r1.bottom);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r1.right, r1.top);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.right, r2.top);
    path.moveTo(r2.right, r2.top);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.bottom);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.left, r2.bottom);
    canvas.drawPath(path, p);
}

From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java

/**
 * Creates a Bitmap image that contains red on white text with a specified margin.
 * @param text Text to be displayed in the image.
 * @return A Bitmap image with the above specification.
 *//*  w w  w . j  a  v a 2 s.c  o m*/
private Bitmap createSampleImage(String text) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setTextSize(TEXT_SIZE);
    Rect rect = new Rect();
    paint.getTextBounds(text, 0, text.length(), rect);
    int w = 2 * MARGIN + rect.right - rect.left;
    int h = 2 * MARGIN + rect.bottom - rect.top;
    Bitmap dest = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas();
    canvas.setBitmap(dest);
    paint.setColor(Color.WHITE);
    canvas.drawPaint(paint);
    paint.setColor(Color.RED);
    canvas.drawText(text, MARGIN - rect.left, MARGIN - rect.top, paint);
    return dest;
}

From source file:com.example.google.maps.dataviz.MainActivity.java

private void addDataToMap() {
    ArrayList<LatLng> coords = new ArrayList<LatLng>();
    ArrayList<Double> samples = new ArrayList<Double>();
    double minElevation = Integer.MAX_VALUE;
    double maxElevation = Integer.MIN_VALUE;

    try {/*  w ww .  j av  a2s .  c  o  m*/
        Resources res = getResources();
        InputStream istream = res.openRawResource(R.raw.elevation);
        byte[] buff = new byte[istream.available()];
        istream.read(buff);
        istream.close();

        String json = new String(buff);
        JSONArray jsonArray = new JSONArray(json);

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject sample = jsonArray.getJSONObject(i);

            double elevation = sample.getDouble("elevation");
            minElevation = elevation < minElevation ? elevation : minElevation;
            maxElevation = elevation > maxElevation ? elevation : maxElevation;

            JSONObject location = sample.getJSONObject("location");
            LatLng position = new LatLng(location.getDouble("lat"), location.getDouble("lng"));

            coords.add(position);
            samples.add(elevation);
        }
    } catch (IOException e) {
        Log.e(this.getClass().getName(), "Error accessing elevation data file.");
        return;
    } catch (JSONException e) {
        Log.e(this.getClass().getName(), "Error processing elevation data (JSON).");
        return;
    }

    for (int i = 0; i < coords.size(); i++) {
        double elevation = samples.get(i);
        int height = (int) (elevation / maxElevation * MARKER_HEIGHT);

        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = Bitmap.createBitmap(MARKER_WIDTH, height, conf);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawPaint(mPaint);

        // Invert the bitmap (top red, bottom blue).
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);

        LatLng position = coords.get(i);
        BitmapDescriptor bitmapDesc = BitmapDescriptorFactory.fromBitmap(bitmap);
        mMap.addMarker(new MarkerOptions().position(position).icon(bitmapDesc).alpha(.8f)
                .title(new DecimalFormat("#.## meters").format(elevation)));
    }
}

From source file:fr.francetv.zoom.share.loader.ZoomLoaderView.java

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

    int sc = canvas.saveLayer(0, 0, mViewWidthPx, mViewHeightPx, null,
            Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
                    | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);

    int mAnimationInValue = (int) mAnimationIn.getAnimatedValue();
    int mAnimationOutValue = mAnimationOut.isRunning() ? (int) mAnimationOut.getAnimatedValue() : 0;

    canvas.drawPaint(mBackgroundPaint);
    canvas.drawArc(mLeftCircleArc, LEFT_START_DEGRE - mAnimationOutValue,
            -mAnimationInValue + mAnimationOutValue, true, mAnimPaint);
    canvas.drawArc(mRightCircleArc, RIGHT_START_DEGRE - mAnimationOutValue,
            -mAnimationInValue + mAnimationOutValue, true, mAnimPaint);
    canvas.drawBitmap(mMaskBitmap, 0, 0, mMaskPaint);
    canvas.restoreToCount(sc);//w  w  w . j av  a  2s.  c  o m
}

From source file:org.connectbot.TerminalView.java

@Override
public void onDraw(Canvas canvas) {
    if (bridge.bitmap != null) {
        // draw the bitmap
        bridge.onDraw();/* w  w  w.  j av a2s.  com*/

        // draw the bridge bitmap if it exists
        canvas.drawBitmap(bridge.bitmap, 0, 0, paint);

        // also draw cursor if visible
        if (bridge.buffer.isCursorVisible()) {
            int cursorColumn = bridge.buffer.getCursorColumn();
            final int cursorRow = bridge.buffer.getCursorRow();

            final int columns = bridge.buffer.getColumns();

            if (cursorColumn == columns)
                cursorColumn = columns - 1;

            if (cursorColumn < 0 || cursorRow < 0)
                return;

            int currentAttribute = bridge.buffer.getAttributes(cursorColumn, cursorRow);
            boolean onWideCharacter = (currentAttribute & VDUBuffer.FULLWIDTH) != 0;

            int x = cursorColumn * bridge.charWidth;
            int y = (bridge.buffer.getCursorRow() + bridge.buffer.screenBase - bridge.buffer.windowBase)
                    * bridge.charHeight;

            // Save the current clip and translation
            canvas.save();

            canvas.translate(x, y);
            canvas.clipRect(0, 0, bridge.charWidth * (onWideCharacter ? 2 : 1), bridge.charHeight);
            canvas.drawPaint(cursorPaint);

            final int deadKey = bridge.getKeyHandler().getDeadKey();
            if (deadKey != 0) {
                canvas.drawText(new char[] { (char) deadKey }, 0, 1, 0, 0, cursorStrokePaint);
            }

            // Make sure we scale our decorations to the correct size.
            canvas.concat(scaleMatrix);

            int metaState = bridge.getKeyHandler().getMetaState();

            if ((metaState & TerminalKeyListener.OUR_SHIFT_ON) != 0)
                canvas.drawPath(shiftCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_SHIFT_LOCK) != 0)
                canvas.drawPath(shiftCursor, cursorPaint);

            if ((metaState & TerminalKeyListener.OUR_ALT_ON) != 0)
                canvas.drawPath(altCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_ALT_LOCK) != 0)
                canvas.drawPath(altCursor, cursorPaint);

            if ((metaState & TerminalKeyListener.OUR_CTRL_ON) != 0)
                canvas.drawPath(ctrlCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_CTRL_LOCK) != 0)
                canvas.drawPath(ctrlCursor, cursorPaint);

            // Restore previous clip region
            canvas.restore();
        }

        // draw any highlighted area
        if (bridge.isSelectingForCopy()) {
            SelectionArea area = bridge.getSelectionArea();
            canvas.save(Canvas.CLIP_SAVE_FLAG);
            canvas.clipRect(area.getLeft() * bridge.charWidth, area.getTop() * bridge.charHeight,
                    (area.getRight() + 1) * bridge.charWidth, (area.getBottom() + 1) * bridge.charHeight);
            canvas.drawPaint(cursorPaint);
            canvas.restore();
        }
    }
}