java类android.graphics.Path的实例源码

SpiderNetView.java 文件源码 项目:Android-Code-Demos 阅读 20 收藏 0 点赞 0 评论 0
private void drawPointsAndFill(Canvas canvas) {
    Path path = new Path();

    path.moveTo(mUnitPointFs[0].x * mOffsets[0] / 100 * mNetLength,
            mUnitPointFs[0].y * mOffsets[0] / 100 * mNetLength);

    for (int i = 0; i < mUnitPointFs.length; i++) {
        /* draw point */
        canvas.drawPoint(mUnitPointFs[i].x * mOffsets[i] / 100 * mNetLength,
                mUnitPointFs[i].y * mOffsets[i] / 100 * mNetLength,
                mPointPaint);
        /* draw line */
        if (i + 1 != mUnitPointFs.length) {
            path.lineTo(mUnitPointFs[i + 1].x * mOffsets[i + 1] / 100 * mNetLength,
                    mUnitPointFs[i + 1].y * mOffsets[i + 1] / 100 * mNetLength);
        } else {
           path.lineTo(mUnitPointFs[0].x * mOffsets[0] / 100 * mNetLength,
                   mUnitPointFs[0].y * mOffsets[0] / 100 * mNetLength);
        }

    }
    path.close();
    canvas.drawPath(path, mFillPaint);
}
BounceBallView.java 文件源码 项目:miaosou 阅读 31 收藏 0 点赞 0 评论 0
private void initData() {

        defaultPadding = 2 * radius + dp2px(2);
        defaultPaddingBottom = 2 * radius + dp2px(15);
        defaultWidth = (int) (2 * defaultPadding + dp2px(200));
        defaultHeight = (int) (defaultPadding + defaultPaddingBottom + dp2px(80));

        paint = new Paint[ballCount];
        for (int i = 0; i < paint.length; i++) {
            paint[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint[i].setColor(ballColor);
            paint[i].setStyle(Paint.Style.FILL);
        }

        path = new Path();
        pathMeasure = new PathMeasure();
        randomBallColors = new int[ballCount];
        randomRadius = new float[ballCount];
        randomTransRatioX = new float[ballCount];
        randomTransRatioY = new float[ballCount];

        translateFraction = new float[ballCount];
        translateAnim = new ValueAnimator[ballCount];

    }
CircularSplashView.java 文件源码 项目:Depth 阅读 18 收藏 0 点赞 0 评论 0
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;
        }
MarkerDrawable.java 文件源码 项目:Musicoco 阅读 20 收藏 0 点赞 0 评论 0
private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners = new float[]{halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize};
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
}
MaterialHeader.java 文件源码 项目:SmartRefresh 阅读 22 收藏 0 点赞 0 评论 0
private void initView(Context context, AttributeSet attrs) {
    setMinimumHeight(DensityUtil.dp2px(100));

    mProgress = new MaterialProgressDrawable(context, this);
    mProgress.setBackgroundColor(CIRCLE_BG_LIGHT);
    mProgress.setAlpha(255);
    mProgress.setColorSchemeColors(0xff0099cc,0xffff4444,0xff669900,0xffaa66cc,0xffff8800);
    mCircleView = new CircleImageView(context,CIRCLE_BG_LIGHT);
    mCircleView.setImageDrawable(mProgress);
    mCircleView.setVisibility(View.GONE);
    addView(mCircleView);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleDiameter = (int) (CIRCLE_DIAMETER * metrics.density);

    mBezierPath = new Path();
    mBezierPaint = new Paint();
    mBezierPaint.setAntiAlias(true);
    mBezierPaint.setStyle(Paint.Style.FILL);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MaterialHeader);
    mShowBezierWave = ta.getBoolean(R.styleable.MaterialHeader_mhShowBezierWave, mShowBezierWave);
    mBezierPaint.setColor(ta.getColor(R.styleable.MaterialHeader_mhPrimaryColor, 0xff11bbff));
    if (ta.hasValue(R.styleable.MaterialHeader_mhShadowRadius)) {
        int radius = ta.getDimensionPixelOffset(R.styleable.MaterialHeader_mhShadowRadius, 0);
        int color = ta.getColor(R.styleable.MaterialHeader_mhShadowColor, 0xff000000);
        mBezierPaint.setShadowLayer(radius, 0, 0, color);
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
    ta.recycle();

}
IconNormalizer.java 文件源码 项目:LaunchEnr 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Returns if the shape of the icon is same as the path.
 * For this method to work, the shape path bounds should be in [0,1]x[0,1] bounds.
 */
private boolean isShape(Path maskPath) {
    // Condition1:
    // If width and height of the path not close to a square, then the icon shape is
    // not same as the mask shape.
    float iconRatio = ((float) mBounds.width()) / mBounds.height();
    if (Math.abs(iconRatio - 1) > BOUND_RATIO_MARGIN) {
        return false;
    }

    // Condition 2:
    // Actual icon (white) and the fitted shape (e.g., circle)(red) XOR operation
    // should generate transparent image, if the actual icon is equivalent to the shape.
    mFileId = mRandom.nextInt();
    mBitmapARGB.eraseColor(Color.TRANSPARENT);
    mCanvasARGB.drawBitmap(mBitmap, 0, 0, mPaintIcon);

    // Fit the shape within the icon's bounding box
    mMatrix.reset();
    mMatrix.setScale(mBounds.width(), mBounds.height());
    mMatrix.postTranslate(mBounds.left, mBounds.top);
    maskPath.transform(mMatrix);

    // XOR operation
    mCanvasARGB.drawPath(maskPath, mPaintMaskShape);

    // DST_OUT operation around the mask path outline
    mCanvasARGB.drawPath(maskPath, mPaintMaskShapeOutline);

    boolean isTrans = isTransparentBitmap(mBitmapARGB);

    // Check if the result is almost transparent
    if (!isTrans) {
        return false;
    }
    return true;
}
FastScrollPopup.java 文件源码 项目:Sprog-App 阅读 23 收藏 0 点赞 0 评论 0
public void draw(Canvas canvas) {
    if (isVisible()) {
        // Draw the fast scroller popup
        int restoreCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mBgBounds.left, mBgBounds.top);
        mTmpRect.set(mBgBounds);
        mTmpRect.offsetTo(0, 0);

        mBackgroundPath.reset();
        mBackgroundRect.set(mTmpRect);

        float[] radii;

        if (Utils.isRtl(mRes)) {
            radii = new float[]{mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, 0, 0};
        } else {

            radii = new float[]{mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, 0, 0, mCornerRadius, mCornerRadius};
        }

        mBackgroundPath.addRoundRect(mBackgroundRect, radii, Path.Direction.CW);

        mBackgroundPaint.setAlpha((int) (mAlpha * 255));
        mTextPaint.setAlpha((int) (mAlpha * 255));
        canvas.drawPath(mBackgroundPath, mBackgroundPaint);
        canvas.drawText(mSectionName, (mBgBounds.width() - mTextBounds.width()) / 2,
                mBgBounds.height() - (mBgBounds.height() - mTextBounds.height()) / 2,
                mTextPaint);
        canvas.restoreToCount(restoreCount);
    }
}
MyView2.java 文件源码 项目:MySelfDemo 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 用 path 拼接的时候  moveTo 这个参数
 *
 * @param canvas
 */
private void drawPaht4(Canvas canvas) {
    Paint paint = new Paint();
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
    Path path = new Path();
    path.lineTo(100, 100);
    path.moveTo(200, 100);  //此为移动到某个点上去  用 moveTo可以移动起始点  =此过程不会绘制图形,不过会移动点
    path.lineTo(200, 0);   // lineTo 都是想对于上个点来说的
    canvas.drawPath(path, paint);
}
VoronoiRegion.java 文件源码 项目:Vorolay 阅读 24 收藏 0 点赞 0 评论 0
private void initPath() {
    path = new Path();

    for (int i = 0; i < points.size(); i++) {
        VoronoiPoint point = points.get(i);
        if (i == 0) {
            path.moveTo((float)point.x, (float)point.y);
            continue;
        }
        path.lineTo((float)point.x, (float)point.y);
    }

    path.close();
}
GlobalActionAutomator.java 文件源码 项目:https-github.com-hyb1996-NoRootScriptDroid 阅读 23 收藏 0 点赞 0 评论 0
private Path pointsToPath(int[][] points) {
    Path path = new Path();
    path.moveTo(scaleX(points[0][0]), scaleY(points[0][1]));
    for (int i = 1; i < points.length; i++) {
        int[] point = points[i];
        path.lineTo(scaleX(point[0]), scaleY(point[1]));
    }
    return path;
}


问题


面经


文章

微信
公众号

扫码关注公众号