本文整理汇总了Java中android.graphics.Path.addOval方法的典型用法代码示例。如果您正苦于以下问题:Java Path.addOval方法的具体用法?Java Path.addOval怎么用?Java Path.addOval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Path
的用法示例。
在下文中一共展示了Path.addOval方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotatedOval
import android.graphics.Path; //导入方法依赖的package包/类
private Bitmap rotatedOval(Bitmap bitmap) {
Bitmap bmp;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Path oval = new Path();
Matrix matrix = new Matrix();
RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height);
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
canvas.drawPath(oval, paint);
return bmp;
}
示例2: onDraw
import android.graphics.Path; //导入方法依赖的package包/类
/**
* Path同样也给我们封装好了一些路径效果,例如圆形,矩形等等,跟canvas.drawXX比较类似,这里就简单介绍下
*
* addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle)
* 添加弧线到路径
*
* addCircle(float x, float y, float radius, Path.Direction dir) 添加圆到路径
*
* addOval(float left, float top, float right, float bottom, Path.Direction dir) 添加椭圆到路径
*
* addRect(float left, float top, float right, float bottom, Path.Direction dir) 添加矩形到路径
*
* 上面的Path.Direction dir参数用来指定绘制时是顺时针还是逆时针,Path.Direction.CCW和Path.Direction.CW分别代表逆时针和顺时针,
* 顺时针和逆时针主要的作用在于不同的时针方向也就决定了不同的路径起始点和终点,其他的参数跟canvas.drawXX是一样的
*/
@Override protected void onDraw(Canvas canvas) {
//设置绘制风格
setViewPaint();
//构建path
Path path = new Path();
//添加弧形到path
path.addArc(100, 100, 300, 300, 0, 270);
//添加圆形到path
path.addCircle(200, 500, 100, Path.Direction.CCW);
//添加矩形到path
path.addRect(100, 700, 300, 800, Path.Direction.CW);
//添加椭圆到path
path.addOval(100, 900, 300, 1000, Path.Direction.CCW);
//绘制path
canvas.drawPath(path, paint);
}
示例3: clippedRotatedOval
import android.graphics.Path; //导入方法依赖的package包/类
private Bitmap clippedRotatedOval(Bitmap bitmap) {
Bitmap bmp;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Path oval = new Path();
Matrix matrix = new Matrix();
Region region = new Region();
RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height);
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
region.setPath(oval, new Region((int) width / 2, 0, (int) width, (int) height));
canvas.drawPath(region.getBoundaryPath(), paint);
return bmp;
}
示例4: getPath
import android.graphics.Path; //导入方法依赖的package包/类
@Override
protected Path getPath(Canvas canvas, Paint paint) {
Path path = new Path();
float cx = ParserHelper.fromPercentageToFloat(mCx, mCanvasWidth, 0, mScale);
float cy = ParserHelper.fromPercentageToFloat(mCy, mCanvasHeight, 0, mScale);
float rx = ParserHelper.fromPercentageToFloat(mRx, mCanvasWidth, 0, mScale);
float ry = ParserHelper.fromPercentageToFloat(mRy, mCanvasHeight, 0, mScale);
RectF oval = new RectF(cx - rx, cy - ry, cx + rx, cy + ry);
path.addOval(oval, Path.Direction.CW);
return path;
}
示例5: heart
import android.graphics.Path; //导入方法依赖的package包/类
private Bitmap heart(Bitmap bitmap) {
Bitmap bmp;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Path oval = new Path();
Matrix matrix = new Matrix();
Region region = new Region();
RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height);
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
region.setPath(oval, new Region((int) width / 2, 0, (int) width, (int) height));
canvas.drawPath(region.getBoundaryPath(), paint);
matrix.reset();
oval.reset();
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(-ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
region.setPath(oval, new Region(0, 0, (int) width / 2, (int) height));
canvas.drawPath(region.getBoundaryPath(), paint);
return bmp;
}