删除绘图点之间的图像

时间:2019-03-28 07:29:36

标签: java android image-processing

在我的应用中,我想在图像上播放视频。用户完成输入时,我会从手指画一条路径。所以问题是我想删除/删除起点和终点之间的所有点。

现在我要这个want this

下面是我的代码 其次是如何自定义视频视图。我想在那个白色区域播放视频。

public class CanvasView  extends View {

    public int width;
    public int height;
    private Bitmap mBitmap,workingBitmap;
    private Canvas mCanvas;
    static Path mPath;
    private Paint mPaint;
    private Paint mBitmapPaint;
    private float mX, mY,startingpoint,endingpoint;
    private static final float TOLERANCE = 5;
    Context context;



    public CanvasView(Context c, AttributeSet attrs) {
        super(c, attrs);
        context = c;
        mPaint = new Paint(Paint.DITHER_FLAG);
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(Color.parseColor("#37A1D1"));
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);
        mPath = new Path();
        mPaint.setStrokeWidth(4f);
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);


    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.home);
        mCanvas = new Canvas(mBitmap.copy(Bitmap.Config.ARGB_8888, true));

    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(mBitmap,0,0,mBitmapPaint);
        canvas.drawPath(mPath, mPaint);
    }


    private void startTouch(float x, float y) {
        mPath.reset();
        mPath.moveTo(x, y);
        startingpoint = x;
        endingpoint = y;
        mX = x;
        mY = y;
    }


    private void moveTouch(float x, float y) {
        float dx = Math.abs(x - mX);
        float dy = Math.abs(y - mY);
        if (dx >= TOLERANCE || dy >= TOLERANCE) {
            mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
            mX = x;
            mY = y;
        }
    }
    private void upTouch() {
        mPath.lineTo(mX, mY);
        mPath.lineTo(startingpoint,endingpoint);
        mCanvas.drawPath(mPath, mPaint);

    }

    //override the onTouchEvent
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        float x = event.getX();
        float y = event.getY();

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startTouch(x, y);
                invalidate();
                break;
            case MotionEvent.ACTION_MOVE:
                moveTouch(x, y);
                invalidate();
                break;
            case MotionEvent.ACTION_UP:
                upTouch();
                invalidate();
                break;
        }
        return true;
    }


}

0 个答案:

没有答案