本文整理匯總了Java中android.graphics.Canvas.drawOval方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.drawOval方法的具體用法?Java Canvas.drawOval怎麽用?Java Canvas.drawOval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawOval方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
float r = CENTER_X - mPaint.getStrokeWidth() * 0.5f;
canvas.translate(CENTER_X, CENTER_X);
canvas.drawOval(new RectF(-r, -r, r, r), mPaint);
canvas.drawCircle(0, 0, CENTER_RADIUS, mCenterPaint);
if (mTrackingCenter) {
int c = mCenterPaint.getColor();
mCenterPaint.setStyle(Paint.Style.STROKE);
if (mHighlightCenter) {
mCenterPaint.setAlpha(0xFF);
} else {
mCenterPaint.setAlpha(0x80);
}
canvas.drawCircle(0, 0,
CENTER_RADIUS + mCenterPaint.getStrokeWidth(),
mCenterPaint);
mCenterPaint.setStyle(Paint.Style.FILL);
mCenterPaint.setColor(c);
}
}
示例2: drawWeightHistory
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawWeightHistory(Canvas canvas) {
Paint weightPaint = new Paint();
weightPaint.setColor(Color.parseColor("#033b7d"));
weightPaint.setStrokeWidth(3);
int circleSize = appContext.getResources().getInteger(R.integer.sizeGraphCircle);
for (Point weightPosition : weightHistory) {
canvas.drawOval(
scaleToXAxis(weightPosition.x),
getHeight() - scaleToYAxis(weightPosition.y) - circleSize,
scaleToXAxis(weightPosition.x) + circleSize,
getHeight() - scaleToYAxis(weightPosition.y),
weightPaint);
}
}
示例3: toOvalBitmap
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* Create a new bitmap that has all pixels beyond the oval shape transparent.
* Old bitmap is recycled.
*/
public static Bitmap toOvalBitmap(@NonNull Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
int color = 0xff424242;
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
RectF rect = new RectF(0, 0, width, height);
canvas.drawOval(rect, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, 0, 0, paint);
bitmap.recycle();
return output;
}
示例4: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(@NonNull Canvas canvas) {
if (mRebuildShader) {
BitmapShader bitmapShader = new BitmapShader(mBitmap, mTileModeX, mTileModeY);
if (mTileModeX == Shader.TileMode.CLAMP && mTileModeY == Shader.TileMode.CLAMP) {
bitmapShader.setLocalMatrix(mShaderMatrix);
}
mBitmapPaint.setShader(bitmapShader);
mRebuildShader = false;
}
if (mOval) {
if (mBorderWidth > 0) {
canvas.drawOval(mDrawableRect, mBitmapPaint);
canvas.drawOval(mBorderRect, mBorderPaint);
} else {
canvas.drawOval(mDrawableRect, mBitmapPaint);
}
} else {
if (any(mCornersRounded)) {
float radius = mCornerRadius;
if (mBorderWidth > 0) {
canvas.drawRoundRect(mDrawableRect, radius, radius, mBitmapPaint);
canvas.drawRoundRect(mBorderRect, radius, radius, mBorderPaint);
redrawBitmapForSquareCorners(canvas);
redrawBorderForSquareCorners(canvas);
} else {
canvas.drawRoundRect(mDrawableRect, radius, radius, mBitmapPaint);
redrawBitmapForSquareCorners(canvas);
}
} else {
canvas.drawRect(mDrawableRect, mBitmapPaint);
if (mBorderWidth > 0) {
canvas.drawRect(mBorderRect, mBorderPaint);
}
}
}
}
示例5: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
// All of our positions are using our internal coordinate system.
// Instead of translating
// them we let Canvas do the work for us.
canvas.translate(mTranslationOffset, mTranslationOffset);
// Draw the color wheel.
canvas.drawOval(mColorWheelRectangle, mColorWheelPaint);
float[] pointerPosition = calculatePointerPosition(mAngle);
// Draw the pointer's "halo"
canvas.drawCircle(pointerPosition[0], pointerPosition[1],
mColorPointerHaloRadius, mPointerHaloPaint);
// Draw the pointer (the currently selected color) slightly smaller on
// top.
canvas.drawCircle(pointerPosition[0], pointerPosition[1],
mColorPointerRadius, mPointerColor);
// Draw the halo of the center colors.
canvas.drawCircle(0, 0, mColorCenterHaloRadius, mCenterHaloPaint);
if (mShowCenterOldColor) {
// Draw the old selected color in the center.
canvas.drawArc(mCenterRectangle, 90, 180, true, mCenterOldPaint);
// Draw the new selected color in the center.
canvas.drawArc(mCenterRectangle, 270, 180, true, mCenterNewPaint);
}
else {
// Draw the new selected color in the center.
canvas.drawArc(mCenterRectangle, 0, 360, true, mCenterNewPaint);
}
}
示例6: createCircleDrawable
import android.graphics.Canvas; //導入方法依賴的package包/類
protected Drawable createCircleDrawable(RectF circleRect, int color) {
final Bitmap bitmap = Bitmap.createBitmap(mDrawableSize, mDrawableSize, Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(color);
canvas.drawOval(circleRect, paint);
return new BitmapDrawable(getResources(), bitmap);
}
示例7: getCircleBitmap
import android.graphics.Canvas; //導入方法依賴的package包/類
public static Bitmap getCircleBitmap(Bitmap bm) {
if (bm == null) return null;
int sice = Math.min((bm.getWidth()), (bm.getHeight()));
Bitmap bitmap = ThumbnailUtils.extractThumbnail(bm, sice, sice);
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xffff0000;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setFilterBitmap(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawOval(rectF, paint);
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth((float) 4);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例8: createMask
import android.graphics.Canvas; //導入方法依賴的package包/類
public Bitmap createMask() {
Bitmap localBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
Canvas localCanvas = new Canvas(localBitmap);
Paint localPaint = new Paint(1);
localPaint.setColor(-16777216);
localCanvas.drawOval(new RectF(0.0f, 0.0f, (float) getWidth(), (float) getHeight()),
localPaint);
return localBitmap;
}
示例9: drawIndicator
import android.graphics.Canvas; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void drawIndicator(Canvas canvas) {
mPaint.setColor(indicatorHolder.getColor());
mPaint.setAlpha(indicatorHolder.getAlpha());
canvas.drawOval(
indicatorHolder.getCenterX() - indicatorHolder.getWidth() / 2,
indicatorHolder.getCenterY() - indicatorHolder.getHeight() / 2,
indicatorHolder.getCenterX() + indicatorHolder.getWidth() / 2,
indicatorHolder.getCenterY() + indicatorHolder.getHeight() / 2,
mPaint
);
}
示例10: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void draw(Canvas canvas) {
int saveCount = canvas.save();
for (int i = 1; i < mBallCount - 1; i++) {
mPaint.setAlpha(MAX_ALPHA);
canvas.drawCircle(mBallRadius * (i * 2 - 1) + mBallSideOffsets, mBallCenterY, mBallRadius, mPaint);
mOvalRect.set(mBallRadius * (i * 2 - 2) + mBallSideOffsets, mHeight - mOvalVerticalRadius * 2,
mBallRadius * (i * 2) + mBallSideOffsets, mHeight);
mPaint.setAlpha(OVAL_ALPHA);
canvas.drawOval(mOvalRect, mPaint);
}
//draw the first ball
mPaint.setAlpha(MAX_ALPHA);
canvas.drawCircle(mBallSideOffsets - mBallRadius - mLeftBallMoveXOffsets,
mBallCenterY - mLeftBallMoveYOffsets, mBallRadius, mPaint);
mOvalRect.set(mBallSideOffsets - mBallRadius - mBallRadius * mLeftOvalShapeRate - mLeftBallMoveXOffsets,
mHeight - mOvalVerticalRadius - mOvalVerticalRadius * mLeftOvalShapeRate,
mBallSideOffsets - mBallRadius + mBallRadius * mLeftOvalShapeRate - mLeftBallMoveXOffsets,
mHeight - mOvalVerticalRadius + mOvalVerticalRadius * mLeftOvalShapeRate);
mPaint.setAlpha(OVAL_ALPHA);
canvas.drawOval(mOvalRect, mPaint);
//draw the last ball
mPaint.setAlpha(MAX_ALPHA);
canvas.drawCircle(mBallRadius * (mBallCount * 2 - 3) + mBallSideOffsets + mRightBallMoveXOffsets,
mBallCenterY - mRightBallMoveYOffsets, mBallRadius, mPaint);
mOvalRect.set(mBallRadius * (mBallCount * 2 - 3) - mBallRadius * mRightOvalShapeRate + mBallSideOffsets + mRightBallMoveXOffsets,
mHeight - mOvalVerticalRadius - mOvalVerticalRadius * mRightOvalShapeRate,
mBallRadius * (mBallCount * 2 - 3) + mBallRadius * mRightOvalShapeRate + mBallSideOffsets + mRightBallMoveXOffsets,
mHeight - mOvalVerticalRadius + mOvalVerticalRadius * mRightOvalShapeRate);
mPaint.setAlpha(OVAL_ALPHA);
canvas.drawOval(mOvalRect, mPaint);
canvas.restoreToCount(saveCount);
}
示例11: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//創建圖片
Bitmap bitmap = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
//生成圖片內容
Canvas canvas1 = new Canvas(bitmap);
Paint paint = new Paint();
//去鋸齒
paint.setAntiAlias(true);
//設置顏色
paint.setColor(Color.RED);
canvas1.drawOval(100, 100, 200, 300, paint);
//將圖片繪製出來
canvas.drawBitmap(bitmap, 0, 0, null);
}
示例12: drawSunShadow
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawSunShadow(Canvas canvas) {
mPaint.setColor(sunShadowColor);
mPaint.setStyle(Paint.Style.FILL);
mRectFSunShadow.set(getMeasuredWidth()/2-sunShadowWidth/2,getMeasuredHeight()- sunShadowHeight,
getMeasuredWidth()/2+sunShadowWidth/2,getMeasuredHeight());
canvas.drawOval(mRectFSunShadow,mPaint);
}
示例13: drawLayers
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawLayers(Canvas canvas, float vx, float vy, List<Layer> layers) {
if (layers != null) {
Paint p = new Paint();
for (Layer layer : layers) {
if (layer.isVisible()) {
if (layer instanceof LayerGroup) {
LayerGroup group = (LayerGroup) layer;
drawLayers(canvas, vx, vy, group.getLayers());
} else if (layer instanceof ShapeLayer) {
ShapeLayer shapeLayer = (ShapeLayer) layer;
p.setColor(shapeLayer.getColorInt());
p.setAlpha(Math.round(layer.getCompOpacity() / 100f * 255));
// Use different canvas draw method depending on shape
if (shapeLayer instanceof RectLayer) {
p.setAntiAlias(false);
canvas.drawRect(
layer.getLeft() + vx,
layer.getTop() + vy,
layer.getRight() + vx,
layer.getBottom() + vy,
p
);
} else if (shapeLayer instanceof TriangleLayer) {
p.setAntiAlias(true);
Path path = new Path();
path.moveTo(layer.getLeft() + vx, layer.getBottom() + vy);
path.lineTo(layer.getRight() + vx, layer.getBottom() + vy);
path.lineTo(layer.getMidX() + vx, layer.getTop() + vy);
canvas.drawPath(path, p);
} else if (shapeLayer instanceof OvalLayer) {
p.setAntiAlias(true);
canvas.drawOval(
layer.getLeft() + vx,
layer.getTop() + vy,
layer.getRight() + vx,
layer.getBottom() + vy,
p
);
}
}
}
}
}
}
示例14: doDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
void doDraw(Canvas canvas, Paint paint) {
mRectF.set(getBounds());
canvas.drawOval(mRectF, paint);
}
示例15: drawNoService
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawNoService(Canvas canvas, int y, Paint paint) {
float dotSize = textSize * 0.1f;
canvas.drawOval(getWidth() * 0.4f - dotSize, y - textSize * 0.35f - dotSize, getWidth() * 0.4f + dotSize, y - textSize * 0.35f + dotSize, paint);
canvas.drawOval(getWidth() * 0.6f - dotSize, y - textSize * 0.35f - dotSize, getWidth() * 0.6f + dotSize, y - textSize * 0.35f + dotSize, paint);
}