MCPcopy Create free account
hub / github.com/GcsSloop/AndroidNote / SetPolyToPoly

Class SetPolyToPoly

CustomView/Advance/Code/SetPolyToPoly.java:24–129  ·  view source on GitHub ↗

Author: GcsSloop Created Date: 16/8/26 Copyright (C) 2016 GcsSloop. GitHub: https://github.com/GcsSloop

Source from the content-addressed store, hash-verified

22 * GitHub: https://github.com/GcsSloop
23 */
24public class SetPolyToPoly extends View{
25 private static final String TAG = "SetPolyToPoly";
26
27 private int testPoint = 0;
28 private int triggerRadius = 180; // 触发半径为180px
29
30 private Bitmap mBitmap; // 要绘制的图片
31 private Matrix mPolyMatrix; // 测试setPolyToPoly用的Matrix
32
33 private float[] src = new float[8];
34 private float[] dst = new float[8];
35
36 private Paint pointPaint;
37
38 public SetPolyToPoly(Context context) {
39 this(context, null);
40 }
41
42 public SetPolyToPoly(Context context, AttributeSet attrs) {
43 this(context, attrs, 0);
44 }
45
46 public SetPolyToPoly(Context context, AttributeSet attrs, int defStyleAttr) {
47 super(context, attrs, defStyleAttr);
48 initBitmapAndMatrix();
49 }
50
51 private void initBitmapAndMatrix() {
52 mBitmap = BitmapFactory.decodeResource(getResources(),
53 R.drawable.poly_test2);
54
55 float[] temp = {0, 0, // 左上
56 mBitmap.getWidth(), 0, // 右上
57 mBitmap.getWidth(), mBitmap.getHeight(), // 右下
58 0, mBitmap.getHeight()}; // 左下
59 src = temp.clone();
60 dst = temp.clone();
61
62 pointPaint = new Paint();
63 pointPaint.setAntiAlias(true);
64 pointPaint.setStrokeWidth(50);
65 pointPaint.setColor(0xffd19165);
66 pointPaint.setStrokeCap(Paint.Cap.ROUND);
67
68 mPolyMatrix = new Matrix();
69 mPolyMatrix.setPolyToPoly(src, 0, src, 0, 4);
70 }
71
72 @Override
73 public boolean onTouchEvent(MotionEvent event) {
74
75 switch (event.getAction()){
76 case MotionEvent.ACTION_MOVE:
77 float tempX = event.getX();
78 float tempY = event.getY();
79
80 // 根据触控位置改变dst
81 for (int i=0; i<testPoint*2; i+=2 ) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected