diff --git a/CustomView/Advance/Code/SetPolyToPoly.java b/CustomView/Advance/Code/SetPolyToPoly.java new file mode 100644 index 0000000..d905ae9 --- /dev/null +++ b/CustomView/Advance/Code/SetPolyToPoly.java @@ -0,0 +1,129 @@ +package com.gcssloop.canvas; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; + +import com.gcssloop.view.utils.CanvasAidUtils; + +/** + * Author: GcsSloop + *
+ * Created Date: 16/8/26 + *
+ * Copyright (C) 2016 GcsSloop. + *
+ * GitHub: https://github.com/GcsSloop
+ */
+public class SetPolyToPoly extends View{
+ private static final String TAG = "SetPolyToPoly";
+
+ private int testPoint = 0;
+ private int triggerRadius = 180; // 触发半径为180px
+
+ private Bitmap mBitmap; // 要绘制的图片
+ private Matrix mPolyMatrix; // 测试setPolyToPoly用的Matrix
+
+ private float[] src = new float[8];
+ private float[] dst = new float[8];
+
+ private Paint pointPaint;
+
+ public SetPolyToPoly(Context context) {
+ this(context, null);
+ }
+
+ public SetPolyToPoly(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public SetPolyToPoly(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ initBitmapAndMatrix();
+ }
+
+ private void initBitmapAndMatrix() {
+ mBitmap = BitmapFactory.decodeResource(getResources(),
+ R.drawable.poly_test2);
+
+ float[] temp = {0, 0, // 左上
+ mBitmap.getWidth(), 0, // 右上
+ mBitmap.getWidth(), mBitmap.getHeight(), // 右下
+ 0, mBitmap.getHeight()}; // 左下
+ src = temp.clone();
+ dst = temp.clone();
+
+ pointPaint = new Paint();
+ pointPaint.setAntiAlias(true);
+ pointPaint.setStrokeWidth(50);
+ pointPaint.setColor(0xffd19165);
+ pointPaint.setStrokeCap(Paint.Cap.ROUND);
+
+ mPolyMatrix = new Matrix();
+ mPolyMatrix.setPolyToPoly(src, 0, src, 0, 4);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+
+ switch (event.getAction()){
+ case MotionEvent.ACTION_MOVE:
+ float tempX = event.getX();
+ float tempY = event.getY();
+
+ // 根据触控位置改变dst
+ for (int i=0; i