android.graphics.Path#addCircle ( )源码实例Demo

下面列出了android.graphics.Path#addCircle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidPhotoFilters   文件: GeneralUtils.java
public static Bitmap generateCircularBitmap(Bitmap input) {

        final int width = input.getWidth();
        final int height = input.getHeight();
        final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        final Path path = new Path();
        path.addCircle(
                (float) (width / 2)
                , (float) (height / 2)
                , (float) Math.min(width, (height / 2))
                , Path.Direction.CCW
        );

        final Canvas canvas = new Canvas(outputBitmap);
        canvas.clipPath(path);
        canvas.drawBitmap(input, 0, 0, null);
        return outputBitmap;
    }
 
源代码2 项目: Depth   文件: CircularSplashView.java
public Bitmap GetBitmapClippedCircle(Bitmap bitmap) {

            final int width = bitmap.getWidth();
            final int height = bitmap.getHeight();
            final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

            final Path path = new Path();
            path.addCircle(
                    (float) (width / 2)
                    , (float) (height / 2)
                    , (float) Math.min(width, (height / 2))
                    , Path.Direction.CCW);

            final Canvas canvas = new Canvas(outputBitmap);
            canvas.clipPath(path);
            canvas.drawBitmap(bitmap, 0, 0, null);
            bitmap.recycle();
            return outputBitmap;
        }
 
源代码3 项目: android   文件: CircleProgress.java
private void drawAlert(Canvas canvas, int radius, float angle) {
    Paint textPaint = new Paint();
    textPaint.setColor(mCircleWhite);
    textPaint.setAntiAlias(true);
    textPaint.setTextSize(getResources().getDimension(R.dimen.out_indicator_size));

    Paint.FontMetricsInt fmi = textPaint.getFontMetricsInt();
    float textRadius = radius - Math.abs(fmi.bottom + fmi.top) / 2;

    Path path = new Path();
    path.addCircle(getCenterX(), getCenterY(), textRadius, Path.Direction.CW);//顺时针绘制(or CCW)

    float circlePathLength = ViewUtils.getCirclePathLength(textRadius,
            (CIRCLE_START_ANGLE + angle / 2));
    circlePathLength -= ViewUtils.getTextWidth(textPaint, mProgressAlert) / 2;
    canvas.drawTextOnPath(String.valueOf(mProgressAlert), path, circlePathLength, 0, textPaint);
}
 
源代码4 项目: Depth   文件: CircularSplashView.java
public Bitmap GetBitmapClippedCircle(Bitmap bitmap) {

            final int width = bitmap.getWidth();
            final int height = bitmap.getHeight();
            final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

            final Path path = new Path();
            path.addCircle(
                    (float) (width / 2)
                    , (float) (height / 2)
                    , (float) Math.min(width, (height / 2))
                    , Path.Direction.CCW);

            final Canvas canvas = new Canvas(outputBitmap);
            canvas.clipPath(path);
            canvas.drawBitmap(bitmap, 0, 0, null);
            bitmap.recycle();
            return outputBitmap;
        }
 
public Bitmap GetBitmapClippedCircle(Bitmap bitmap) {

      final int width = bitmap.getWidth();
      final int height = bitmap.getHeight();
      final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

      final Path path = new Path();
      path.addCircle((float) (width / 2), (float) (height / 2),
          (float) Math.min(width, (height / 2)), Path.Direction.CCW);

      final Canvas canvas = new Canvas(outputBitmap);
      canvas.clipPath(path);
      canvas.drawBitmap(bitmap, 0, 0, null);
      bitmap.recycle();
      return outputBitmap;
    }
 
源代码6 项目: AndroidPhotoFilters   文件: GeneralUtils.java
public static Bitmap generateCircularBitmap(Bitmap input) {

        final int width = input.getWidth();
        final int height = input.getHeight();
        final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        final Path path = new Path();
        path.addCircle(
                (float) (width / 2)
                , (float) (height / 2)
                , (float) Math.min(width, (height / 2))
                , Path.Direction.CCW
        );

        final Canvas canvas = new Canvas(outputBitmap);
        canvas.clipPath(path);
        canvas.drawBitmap(input, 0, 0, null);
        return outputBitmap;
    }
 
源代码7 项目: XRadarView   文件: XRadarView.java
private void drawPolygon(Canvas canvas) {
    Path path = new Path();
    float r = radius / layerCount;
    for (int i = layerCount; i >= 1; i--) {
        float curR = r * i;
        path.reset();
        if (isCircle) {
            path.addCircle(centerX, centerY, curR, Path.Direction.CW);
        } else {
            for (int j = 0; j < count; j++) {
                if (j == 0) {
                    path.moveTo(centerX, centerY - curR);
                } else {
                    path.lineTo((float) (centerX + Math.cos(angle * j + Math.PI / 2) * curR), (float) (centerY - Math.sin(angle * j + Math.PI / 2) * curR));
                }
            }
            path.close();
        }
        canvas.drawPath(path, cobwebPaint);
    }
}
 
源代码8 项目: fab   文件: RippleEffectDrawer.java
/**
 * Returns the clipped path, which clips the ripple circle so that it doesn't goes beyond
 * the <b>Action Button</b> circle
 *
 * @return clipped path, which clips the ripple circle
 */
private Path getCircleClipPath() {
	Path path = new Path();
	path.addCircle(getActionButton().calculateCenterX(), getActionButton().calculateCenterY(),
			getActionButton().calculateCircleRadius(), Path.Direction.CW);
	return path;
}
 
源代码9 项目: Status   文件: CircleColorView.java
@Override
public void render(Canvas canvas) {
    int size = Math.min(canvas.getWidth(), canvas.getHeight());

    Path path = new Path();
    path.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, size / 2, Path.Direction.CW);
    canvas.clipPath(path);

    super.render(canvas);

    canvas.drawCircle(getWidth() / 2, getHeight() / 2, (size / 2) - (outlineSize / 2), outlinePaint);
}
 
源代码10 项目: JNChartDemo   文件: RadarChartRenderer.java
public void drawHighlightCircle(Canvas c,
                            PointF point,
                            float innerRadius,
                            float outerRadius,
                            int fillColor,
                            int strokeColor,
                            float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = new Path();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
@Override
protected void initData() {

    Path path = new Path();
    path.moveTo(0,0);
    path.addCircle(40,40,30, Path.Direction.CW);
    pathAnimView1.setSourcePath(PathParserUtils.getPathFromArrayFloatList(StoreHousePath.getPath("pathview")));
    pathAnimView1.startAnim();

}
 
源代码12 项目: android-kline   文件: RadarChartRenderer.java
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
源代码14 项目: focus-android   文件: ShiftDrawable.java
private void updateBounds() {
    final Rect b = getBounds();
    final int width = (int) ((float) b.width() * getLevel() / MAX_LEVEL);
    final float radius = b.height() / 2f;
    mVisibleRect.set(b.left, b.top, b.left + width, b.height());

    // draw round to head of progressbar. I know it looks stupid, don't blame me now.
    mPath = new Path();
    mPath.addRect(b.left, b.top, b.left + width - radius, b.height(), Path.Direction.CCW);
    mPath.addCircle(b.left + width - radius, radius, radius, Path.Direction.CCW);
}
 
源代码15 项目: NetKnight   文件: RadarChartRenderer.java
public void drawHighlightCircle(Canvas c,
                            PointF point,
                            float innerRadius,
                            float outerRadius,
                            int fillColor,
                            int strokeColor,
                            float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = new Path();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
源代码16 项目: art   文件: ARTShapeShadowNode.java
/**
 * Creates a {@link Path} from an array of instructions constructed by JS
 * (see ARTSerializablePath.js). Each instruction starts with a type (see PATH_TYPE_*) followed
 * by arguments for that instruction. For example, to create a line the instruction will be
 * 2 (PATH_LINE_TO), x, y. This will draw a line from the last draw point (or 0,0) to x,y.
 *
 * @param data the array of instructions
 * @return the {@link Path} that can be drawn to a canvas
 */
private Path createPath(float[] data) {
  Path path = new Path();
  path.moveTo(0, 0);
  int i = 0;
  while (i < data.length) {
    int type = (int) data[i++];
    switch (type) {
      case PATH_TYPE_MOVETO:
        path.moveTo(data[i++] * mScale, data[i++] * mScale);
        break;
      case PATH_TYPE_CLOSE:
        path.close();
        break;
      case PATH_TYPE_LINETO:
        path.lineTo(data[i++] * mScale, data[i++] * mScale);
        break;
      case PATH_TYPE_CURVETO:
        path.cubicTo(
            data[i++] * mScale,
            data[i++] * mScale,
            data[i++] * mScale,
            data[i++] * mScale,
            data[i++] * mScale,
            data[i++] * mScale);
        break;
      case PATH_TYPE_ARC:
      {
        float x = data[i++] * mScale;
        float y = data[i++] * mScale;
        float r = data[i++] * mScale;
        float start = (float) Math.toDegrees(data[i++]);
        float end = (float) Math.toDegrees(data[i++]);

        boolean counterClockwise = !(data[i++] == 1f);
        float sweep = end - start;
        if (Math.abs(sweep) >= 360) {
          path.addCircle(x, y, r, counterClockwise ? Path.Direction.CCW : Path.Direction.CW);
        } else {
          sweep = modulus(sweep, 360);
          if (counterClockwise && sweep < 360) {
            // Counter-clockwise sweeps are negative
            sweep = -1 * (360 - sweep);
          }

          RectF oval = new RectF(x - r, y - r, x + r, y + r);
          path.arcTo(oval, start, sweep);
        }
        break;
      }
      default:
        throw new JSApplicationIllegalArgumentException(
            "Unrecognized drawing instruction " + type);
    }
  }
  return path;
}
 
源代码17 项目: Lobsterpicker   文件: LobsterPicker.java
private void init(Context context, AttributeSet attrs, int defStyle) {
    final TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.LobsterPicker, defStyle, 0);
    final Resources b = context.getResources();

    int thickness = a.getDimensionPixelSize(
            R.styleable.LobsterPicker_color_wheel_thickness,
            b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
    radius = a.getDimensionPixelSize(
            R.styleable.LobsterPicker_color_wheel_radius,
            b.getDimensionPixelSize(R.dimen.color_wheel_radius));
    pointerRadius = a.getDimensionPixelSize(
            R.styleable.LobsterPicker_color_wheel_pointer_radius,
            b.getDimensionPixelSize(R.dimen.color_wheel_pointer_radius));
    historyRadius = a.getDimensionPixelSize(
            R.styleable.LobsterPicker_color_history_radius,
            b.getDimensionPixelSize(R.dimen.color_history_radius));
    colorHistoryEnabled = a.getBoolean(
            R.styleable.LobsterPicker_color_history_enabled,
            false);
    int pointerShadowRadius = a.getDimensionPixelSize(
            R.styleable.LobsterPicker_color_wheel_pointer_shadow_radius,
            b.getDimensionPixelSize(R.dimen.color_wheel_pointer_shadow_radius));
    int pointerShadowColor = a.getColor(R.styleable.LobsterPicker_color_wheel_pointer_shadow,
            b.getColor(R.color.lobsterpicker_pointer_shadow));
    int schemeRes = a.getResourceId(R.styleable.LobsterPicker_color_wheel_scheme,
            R.drawable.default_pallete);

    a.recycle();

    decorators = new ArrayList<>();
    listeners = new ArrayList<>();

    decorators.add(updateDecorator);

    wheelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    wheelPaint.setStyle(Paint.Style.STROKE);
    wheelPaint.setStrokeWidth(thickness);

    pointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    pointerPaint.setStyle(Paint.Style.FILL);

    historyPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    historyPaint.setStyle(Paint.Style.FILL);

    Paint pointerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    pointerShadowPaint.setStyle(Paint.Style.FILL);
    pointerShadowPaint.setColor(pointerShadowColor);

    //Predraw the pointers shadow
    pointerShadow = Bitmap.createBitmap(pointerShadowRadius * 2, pointerShadowRadius * 2, Bitmap.Config.ARGB_8888);
    Canvas pointerShadowCanvas = new Canvas(pointerShadow);
    pointerShadowCanvas.drawCircle(pointerShadowRadius, pointerShadowRadius, pointerShadowRadius, pointerShadowPaint);

    //Outer wheel ring
    largeRadiusPath = new Path();
    largeRadiusPath.addCircle(0, 0, radius + thickness / 2, Path.Direction.CW);
    largeRadiusPath.close();

    //inner wheel ring
    smallRadiusPath = new Path();
    smallRadiusPath.addCircle(0, 0, radius - thickness / 2, Path.Direction.CW);
    smallRadiusPath.close();

    //Default color adapter
    adapter = new BitmapColorAdapter(context, schemeRes);
    updateColorAdapter();

    invalidate();
}
 
源代码18 项目: ShapeView   文件: CirclePath.java
@Override
public void setClipPath(Path path, int width, int height) {
    path.addCircle(width / 2f, height / 2f, Math.min(width / 2f, height / 2f), Path.Direction.CW);
}
 
源代码19 项目: GLEXP-Team-onebillion   文件: OC_Sorting_S4.java
public void setSceneXX(String scene)
{
    if (totalObjectCount == 0)
    {
        deleteControls("obj.*");
        if (collar != null)
            collar.hide();
    }
    super.setSceneXX(scene);

    currentPaintPot = null;
    String potName = eventAttributes.get("targetpot");
    if (potName != null)
    {
        correctPaintPot = objectDict.get(potName);
        Map<String,Object> targetAttrs = correctPaintPot.attributes();
        correctColour = OBUtils.colorFromRGBString((String)targetAttrs.get("fillcolour"));
        correctObjArray = filterControls(String.format("%s.*",eventAttributes.get("targetitem")));
    }
    targets = filterControls("objj.*");
    if (totalObjectCount == 0)
    {
        totalObjectCount = targets.size();
        for (OBControl obj : targets)
        {
            obj.setDoubleSided(true);
            obj.texturise(false,this);
        }
    }
    pots = filterControls("objpot.*");
    if (collar == null)
    {
        float w = pots.get(0).width()+applyGraphicScale(4f);
        Path p = new Path();
        p.addCircle(w/2, w/2, w/2, Path.Direction.CCW);
        collar = new OBPath(p);
        //collar.setLineWidth(applyGraphicScale(4f));
        collar.sizeToBoundingBoxIncludingStroke();
        collar.setFillColor(Color.GRAY);
        collar.setZPosition(pots.get(0).zPosition()-0.01f);
        attachControl(collar);
        collar.hide();
    }
}
 
源代码20 项目: SpotifyTray-Android   文件: Utils.java
/**
 * Takes an inputstream, loads a bitmap optimized of space and then crops it for the view.
 * @param iStream Inputstream to the image.
 * @param containerHeight Height of the image holder container. 
 * @param containerWidth Width of the image holder container.
 * @return Cropped/masked bitmap.
 */
public static Bitmap loadMaskedBitmap(InputStream iStream, int containerHeight, int containerWidth){
	
	// Load image data before loading the image itself.
	BitmapFactory.Options bmOptions = new BitmapFactory.Options();
	bmOptions.inJustDecodeBounds = true;
	
	BitmapFactory.decodeStream(iStream,null,bmOptions);
	
	int photoH = bmOptions.outHeight;
	int photoW = bmOptions.outWidth;
	
	// Find a suitable scalefactor to load the smaller bitmap, and then set the options.
	int scaleFactor = Math.min(photoH/containerHeight, photoW/containerHeight);
	bmOptions.inJustDecodeBounds = false;
	bmOptions.inSampleSize = scaleFactor;
	bmOptions.inPurgeable = true;

	// Load the square region out of the bitmap.
	Bitmap bmap=null;
	BitmapRegionDecoder decoder;
	try {
		iStream.reset();
		decoder = BitmapRegionDecoder.newInstance(iStream, false);
		bmap = decoder.decodeRegion(new Rect(0, 0, Math.min(photoH, photoW), Math.min(photoH, photoW)),bmOptions);
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	// Calculate new width of the bitmap based on the width of the container
	int bitmapNewWidth = (bmap.getWidth()*containerWidth)/containerHeight;   
	
	// Produce clipping mask on the canvas and draw the bitmap 
	Bitmap targetBitmap = Bitmap.createBitmap(bitmapNewWidth, bmap.getHeight(), bmap.getConfig());
	Canvas canvas = new Canvas(targetBitmap);
	Path path = new Path();
	path.addCircle(bmap.getWidth() / 2, bmap.getHeight() / 2, bmap.getWidth() / 2, Path.Direction.CCW);
	canvas.clipPath(path);
	canvas.drawBitmap(bmap, 0, 0, null);

	// Retrieve the clipped bitmap and return
	return targetBitmap;
}