當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.drawCircle方法代碼示例

本文整理匯總了Java中android.graphics.Canvas.drawCircle方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.drawCircle方法的具體用法?Java Canvas.drawCircle怎麽用?Java Canvas.drawCircle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.drawCircle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: transform

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());

    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
    if (squaredBitmap != source) {
        source.recycle();
    }

    Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setAntiAlias(true);

    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);

    squaredBitmap.recycle();
    return bitmap;
}
 
開發者ID:NarendraSickarwar,項目名稱:FirebasePost,代碼行數:27,代碼來源:RoundedTransformation.java

示例2: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas canvas) {
  canvas.drawPaint(backgroundPaint);

  if (this.liveStrength == null) {
    // Nothing to draw yet...
    return;
  }

  float midX = canvas.getWidth() / 2f;
  float midY = canvas.getHeight() / 2f;
  float rad = Math.min(midX / 4f, midY);
  for (int i = 0; i < 4; i++) {
    float atX = midX + (i * 2 - 3) * rad; // i = [0, 1, 2, 3] -> [-3, -1, 1, 3]
    Paint paint = paintForStrength(liveStrength.getChannelStatus(i));
    canvas.drawCircle(atX, midY, rad * PADDING, paint);
  }
}
 
開發者ID:padster,項目名稱:Muse-EEG-Toolkit,代碼行數:19,代碼來源:ConnectionStrengthView.java

示例3: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	if (x != -1) {
		
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setColor(makePressColor());
		canvas.drawCircle(x, y, radius, paint);
		if(radius > getHeight()/rippleSize)
			radius += rippleSpeed;
		if(radius >= getWidth()){
			x = -1;
			y = -1;
			radius = getHeight()/rippleSize;
			if(onClickListener != null&& clickAfterRipple)
				onClickListener.onClick(this);
		}
		invalidate();
	}		
	
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:23,代碼來源:ButtonFlat.java

示例4: drawIcon

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void drawIcon(Canvas canvas, float fraction, Drawable drawable, int colorOfIcon,
                     WidthAndHeightOfView widthAndHeightOfView) {
    int centerX = widthAndHeightOfView.getWidth() / 2;
    int centerY = widthAndHeightOfView.getHeight() / 2 - 150;
    canvas.save();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    float newFraction = (fraction - 0.65f) / 0.35f;
    paint.setColor(Color.parseColor("#e53935"));
    canvas.drawCircle(centerX, centerY - 50, 100 * (1 - newFraction), paint);
    paint.setColor(Color.parseColor("#fdd835"));
    canvas.drawCircle(centerX -35, centerY + 35,100 * (1 - newFraction), paint);
    paint.setColor(Color.parseColor("#1e88e5"));
    canvas.drawCircle(centerX + 35, centerY + 35, 100 * (1 - newFraction), paint);
    canvas.restore();
    canvas.save();
    Path path = new Path();
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    Matrix matrix = new Matrix();
    matrix.postScale(1.7f, 1.7f, centerX, centerY);
    canvas.concat(matrix);
    path.addCircle(centerX, centerY, bitmap.getHeight() * 1.5f * newFraction, Path.Direction.CW);
    canvas.clipPath(path);
    canvas.drawBitmap(bitmap, centerX - bitmap.getWidth() / 2, centerY - bitmap.getHeight() / 2, paint);
    canvas.restore();
}
 
開發者ID:JoshuaRogue,項目名稱:FancyView,代碼行數:27,代碼來源:RYBDrawStrategyStateTwo.java

示例5: circleCrop

import android.graphics.Canvas; //導入方法依賴的package包/類
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    float r = size / 2f;
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#F9F9F9"));
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(r, r, r, paint);
    paint.reset();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
開發者ID:YunzhanghuOpen,項目名稱:redpacketui-open,代碼行數:24,代碼來源:CircleTransform.java

示例6: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
/**
 * Draw the progress spinner
 */
public void draw(Canvas c, Rect bounds) {

    mCirclePaint.setColor(mBackgroundColor);
    mCirclePaint.setAlpha(mAlpha);

    c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2, mCirclePaint);

    final RectF arcBounds = mTempBounds;
    arcBounds.set(bounds);
    arcBounds.inset(mStrokeInset, mStrokeInset);
    final float startAngle = (mStartTrim + mRotation) * 360;
    final float endAngle = (mEndTrim + mRotation) * 360;
    float sweepAngle = endAngle - startAngle;
    mArcPaint.setColor(mColors[mColorIndex]);
    mArcPaint.setAlpha(mAlpha);
    c.drawArc(arcBounds, startAngle, sweepAngle, false, mArcPaint);
    drawTriangle(c, startAngle, sweepAngle, bounds);
}
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:22,代碼來源:MaterialProgressDrawable.java

示例7: cropCircle

import android.graphics.Canvas; //導入方法依賴的package包/類
public Bitmap cropCircle(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());

	paint.setAntiAlias(true);
	canvas.drawARGB(0, 0, 0, 0);
	paint.setColor(color);
	canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
			bitmap.getWidth() / 2, paint);
	paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
	canvas.drawBitmap(bitmap, rect, rect, paint);
	return output;
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:18,代碼來源:ButtonFloat.java

示例8: getCroppedBitmap

import android.graphics.Canvas; //導入方法依賴的package包/類
public Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.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());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
 
開發者ID:asif-patel,項目名稱:ImageMagnifier,代碼行數:19,代碼來源:BrushView.java

示例9: toRound

import android.graphics.Canvas; //導入方法依賴的package包/類
/**
 * 轉為圓形圖片
 *
 * @param src     源圖片
 * @param recycle 是否回收
 * @return 圓形圖片
 */
public static Bitmap toRound(Bitmap src, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int radius = Math.min(width, height) >> 1;
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    Paint paint = new Paint();
    Canvas canvas = new Canvas(ret);
    Rect rect = new Rect(0, 0, width, height);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(width >> 1, height >> 1, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
開發者ID:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:25,代碼來源:ImageUtils.java

示例10: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {

    float height = getMeasuredHeight();

    float outerRadius = badgeRadius * OUTER_RADIUS_MULTIPLIER;

    //draw background
    canvas.drawCircle(outerRadius, outerRadius, outerRadius, backgroundPaint);
    canvas.drawRect(outerRadius, 0, textWidth + (2 * space) + (2 * outerRadius), outerRadius * 2, backgroundPaint);
    canvas.drawCircle(textWidth + (2 * space) + (2 * outerRadius), outerRadius, outerRadius, backgroundPaint);

    //draw badge
    canvas.drawCircle(outerRadius, outerRadius, badgeRadius, badgePaint);

    canvas.drawText(text, (outerRadius * 2) + space, outerRadius + textPaint.descent() * 1.2f, textPaint);
}
 
開發者ID:Protino,項目名稱:CodeWatch,代碼行數:18,代碼來源:BadgeView.java

示例11: drawPoint

import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawPoint(Canvas canvas) {
    int height = getHeight() - textSize * 4;
    int x = getWidth() / 2;
    int y = (int) (height - height * (temperatureDay - minTemp) * 1.0f / (maxTemp - minTemp)) + textSize * 2;
    int x2 = getWidth() / 2;
    int y2 = (int) (height - height * (temperatureNight - minTemp) * 1.0f / (maxTemp - minTemp)) + textSize * 2;
    xPointDay = x;
    yPointDay = y;
    xPointNight = x2;
    yPointNight = y2;
    mWidth = getWidth();
    canvas.drawCircle(x, y, radius, pointPaint);
    canvas.drawCircle(x2, y2, radius, pointPaint);
}
 
開發者ID:yangchong211,項目名稱:YCWeather,代碼行數:15,代碼來源:TemperatureView.java

示例12: drawPress

import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawPress(Canvas canvas) {

        if(mShapeType == 0){
            canvas.drawCircle(mWidth/2, mHeight/2, mWidth/2, mPressPaint);
        }else if (mShapeType == 1) {
            RectF rectF = new RectF(0, 0, mWidth, mHeight);
            canvas.drawRoundRect(rectF, mRadius, mRadius, mPressPaint);
        }
    }
 
開發者ID:dufangyu1990,項目名稱:LeCatApp,代碼行數:10,代碼來源:MLImageView.java

示例13: drawPointInterfere

import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawPointInterfere(Canvas canvas){
    for (int i = 0; i < pointInterfereQuantity; i++) {
        bgPaint.setColor(randomColor());
        interferPoint=randomPoint();
        canvas.drawCircle(interferPoint.x,interferPoint.y,random.nextInt(3)+1,bgPaint);
    }

}
 
開發者ID:againstsky,項目名稱:pictureverification,代碼行數:9,代碼來源:VerificationCodeView.java

示例14: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, Paint paint) {
    float circleSpacing=4;
    for (int i = 0; i < 3; i++) {
        paint.setAlpha(alphaInts[i]);
        canvas.scale(scaleFloats[i],scaleFloats[i],getWidth()/2,getHeight()/2);
        canvas.drawCircle(getWidth()/2,getHeight()/2,getWidth()/2-circleSpacing,paint);
    }
}
 
開發者ID:magicbaby810,項目名稱:SRecyclerView,代碼行數:10,代碼來源:BallScaleMultipleIndicator.java

示例15: drawPoint

import android.graphics.Canvas; //導入方法依賴的package包/類
/**
 * 畫密碼點
 */
private void drawPoint(Canvas canvas) {
    if (pointRadius > 0) {
        paint.setColor(codeColor);
        for (int i = 0; i < code.length(); i++) {
            final float left = unitWidth * i + dividerWidth * i + borderWidth;
            canvas.drawCircle(left + unitWidth / 2, getHeight() / 2, pointRadius, paint);
        }
    }
}
 
開發者ID:KungFuBrother,項目名稱:WeChatPwd,代碼行數:13,代碼來源:CodeView.java


注:本文中的android.graphics.Canvas.drawCircle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。