易网时代-编程资源站
Welcome
微信登录
编程资源
图片资源库
蚂蚁家优选
PDF转换器
软件资源
软件开发
、
小程序制作
、
系统集成与运维
、
空间租用
、
硬件开发
、
视频监控
、
技术咨询与支持
——联系电话:0311-88999002/88999003
首页
/
操作系统
/
Linux
/
Android Clipping
public
class
Clipping
extends
Activity {
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(
new
SampleView(
this
));
}
private
static
class
SampleView
extends
View {
private
Paint mPaint;
private
Path mPath;
public
SampleView(Context context) {
super
(context);
setFocusable(
true
);
mPaint =
new
Paint();
mPaint.setAntiAlias(
true
);
mPaint.setStrokeWidth(
6
);
mPaint.setTextSize(
16
);
mPaint.setTextAlign(Paint.Align.RIGHT);
mPath =
new
Path();
}
private
void
drawScene(Canvas canvas) {
canvas.clipRect(
0
,
0
,
100
,
100
);
canvas.drawColor(Color.WHITE);
mPaint.setColor(Color.RED);
canvas.drawLine(
0
,
0
,
100
,
100
, mPaint);
mPaint.setColor(Color.GREEN);
canvas.drawCircle(
30
,
70
,
30
, mPaint);
mPaint.setColor(Color.BLUE);
canvas.drawText(
"Clipping"
,
100
,
30
, mPaint);
}
@Override
protected
void
onDraw(Canvas canvas) {
canvas.drawColor(Color.GRAY);
canvas.save();
canvas.translate(
10
,
10
);
drawScene(canvas);
canvas.restore();
canvas.save();
canvas.translate(
160
,
10
);
canvas.clipRect(
10
,
10
,
90
,
90
);
canvas.clipRect(
30
,
30
,
70
,
70
, Region.Op.DIFFERENCE);
drawScene(canvas);
canvas.restore();
canvas.save();
canvas.translate(
10
,
160
);
mPath.reset();
canvas.clipPath(mPath);
// makes the clip empty
mPath.addCircle(
50
,
50
,
50
, Path.Direction.CCW);
canvas.clipPath(mPath, Region.Op.REPLACE);
drawScene(canvas);
canvas.restore();
canvas.save();
canvas.translate(
160
,
160
);
canvas.clipRect(
0
,
0
,
60
,
60
);
canvas.clipRect(
40
,
40
,
100
,
100
, Region.Op.UNION);
drawScene(canvas);
canvas.restore();
canvas.save();
canvas.translate(
10
,
310
);
canvas.clipRect(
0
,
0
,
60
,
60
);
canvas.clipRect(
40
,
40
,
100
,
100
, Region.Op.XOR);
drawScene(canvas);
canvas.restore();
canvas.save();
canvas.translate(
160
,
310
);
canvas.clipRect(
0
,
0
,
60
,
60
);
canvas.clipRect(
40
,
40
,
100
,
100
, Region.Op.REVERSE_DIFFERENCE);
drawScene(canvas);
canvas.restore();
}
}
}
收藏该网址
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图