Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我想在跟随手指的同时画一条线_Android - Fatal编程技术网

Android 我想在跟随手指的同时画一条线

Android 我想在跟随手指的同时画一条线,android,Android,基本上,我拍摄屏幕截图并在其上应用裁剪,我使用手指选择裁剪区域以绘制要裁剪的部分。当我向左移动手指时,会出现线条,但我希望线条跟随我的手指创建一个自定义视图,您可以在其上绘制线条。由于此视图似乎应该显示在图像上方,因此最好使用相同的Framelayout将其扩展。并将其放置在图像上方 指线类 public boolean onTouchEvent(MotionEvent event) { //Log.e(Codistan_Tag, "Touch Event: " + MotionEve

基本上,我拍摄屏幕截图并在其上应用裁剪,我使用手指选择裁剪区域以绘制要裁剪的部分。当我向左移动手指时,会出现线条,但我希望线条跟随我的手指

创建一个自定义视图,您可以在其上绘制线条。由于此视图似乎应该显示在图像上方,因此最好使用相同的Framelayout将其扩展。并将其放置在图像上方

指线类

 public boolean onTouchEvent(MotionEvent event) {
    //Log.e(Codistan_Tag, "Touch Event: " + MotionEvent.actionToString(event.getAction()));
    if(isImageReady) {

        if(isSelectionDragEnabled)
            mPanListener.onTouchEvent(event);

        if (isZoomEnabled) {
            if(event.getAction() == MotionEvent.ACTION_DOWN){
                anchor_scale = mScaleFactor;
            }
            mScaleDetector.onTouchEvent(event);
            mPanListener.onTouchEvent(event);
        }
        else {
            switch (event.getAction()) {
                case MotionEvent.ACTION_POINTER_3_DOWN:
                    break;
                case MotionEvent.ACTION_POINTER_2_DOWN:
                    break;
                case MotionEvent.ACTION_POINTER_1_UP:

                    break;
                case MotionEvent.ACTION_DOWN:

                    if (isSelectionToolEnabled)
                        isDrawFinished = false;

                    orig_x = event.getX();
                    orig_y = event.getY();

                    //Log.e(Codistan_Tag, "-------ORIGIN-------s: " + String.valueOf(orig_x) + " " + String.valueOf(orig_y));

                    orig_x = (orig_x - (dest.left));
                    orig_y = (orig_y - (dest.top));

                    if(java.lang.Math.round(mScaleFactor) > 2) {
                        orig_x += (scale_cur_x * (riz_scale));
                        orig_y += (scale_cur_y * (riz_scale));
                    } else {
                        orig_x += (scale_cur_x);
                        orig_y += (scale_cur_y);
                    }

                    orig_x /= java.lang.Math.round(mScaleFactor);
                    orig_y /= java.lang.Math.round(mScaleFactor);

                    orig_x *= scale;
                    orig_y *= scale;

                    //mSelectionTaskManager.setOrigin((int) orig_x, (int) orig_y);
                    if(isSelectionToolEnabled)
                        MovementStack.add(new Pair((int)orig_x, (int)orig_y));

                    Log.e(Codistan_Tag, "Codistan Origins: " + String.valueOf(orig_x) + ", " + String.valueOf(orig_y));

                    break;
                case MotionEvent.ACTION_MOVE:
                    max_dist = dist * scale;

                    if (event.getAction() != 1) {
                        move_x = event.getX();
                        move_y = event.getY();

                        //Log.e(Codistan_Tag, "Move: " + String.valueOf(move_x) + ", " + String.valueOf(move_y));

                        move_x = (move_x - dest.left);
                        move_y = (move_y - dest.top);



                        if(java.lang.Math.round(mScaleFactor) > 2) {
                            move_x += (scale_cur_x * riz_scale);
                            move_y += (scale_cur_y * riz_scale);
                        } else {
                            move_x += (scale_cur_x);
                            move_y += (scale_cur_y);
                        }

                        move_x /= java.lang.Math.round(mScaleFactor);
                        move_y /= java.lang.Math.round(mScaleFactor);

                        move_x *= scale;
                        move_y *= scale;

                        Log.e(Codistan_Tag, "Codistan Move: " + String.valueOf(move_x) + ", " + String.valueOf(move_y));

                        if (move_x >= 0 && move_y >= 0) {
                            if (!isSelectionToolEnabled && isDistortionEnabled) {
                                warpPhotoFromC(image, height, width, max_dist/mScaleFactor, orig_x, orig_y, move_x, move_y);
                                first++;
                                distortedBmp.setPixels(image, 0, width, 0, 0, width, height);
                                fg = false;
                            } else {
                                //Cut Tool Enabled
                                distortedBmp.setPixels(image, 0, width, 0, 0, width, height);
                                MovementStack.add(new Pair((int) move_x, (int) move_y));

                            }
                        }
                    }
                    orig_x = move_x;
                    orig_y = move_y;
                    break;
                case MotionEvent.ACTION_UP:
                    if (isSelectionToolEnabled)
                        isDrawFinished = true;
                    break;
            }
        }
        v.invalidate();
    }
    return true;
}

注意:不要忘记调用invalidate(),因为它将负责调用onDraw

创建一个自定义视图,您可以在其上绘制线条。由于此视图似乎应该显示在图像上方,因此最好使用相同的Framelayout扩展它。并将其放置在图像上方

指线类

 public boolean onTouchEvent(MotionEvent event) {
    //Log.e(Codistan_Tag, "Touch Event: " + MotionEvent.actionToString(event.getAction()));
    if(isImageReady) {

        if(isSelectionDragEnabled)
            mPanListener.onTouchEvent(event);

        if (isZoomEnabled) {
            if(event.getAction() == MotionEvent.ACTION_DOWN){
                anchor_scale = mScaleFactor;
            }
            mScaleDetector.onTouchEvent(event);
            mPanListener.onTouchEvent(event);
        }
        else {
            switch (event.getAction()) {
                case MotionEvent.ACTION_POINTER_3_DOWN:
                    break;
                case MotionEvent.ACTION_POINTER_2_DOWN:
                    break;
                case MotionEvent.ACTION_POINTER_1_UP:

                    break;
                case MotionEvent.ACTION_DOWN:

                    if (isSelectionToolEnabled)
                        isDrawFinished = false;

                    orig_x = event.getX();
                    orig_y = event.getY();

                    //Log.e(Codistan_Tag, "-------ORIGIN-------s: " + String.valueOf(orig_x) + " " + String.valueOf(orig_y));

                    orig_x = (orig_x - (dest.left));
                    orig_y = (orig_y - (dest.top));

                    if(java.lang.Math.round(mScaleFactor) > 2) {
                        orig_x += (scale_cur_x * (riz_scale));
                        orig_y += (scale_cur_y * (riz_scale));
                    } else {
                        orig_x += (scale_cur_x);
                        orig_y += (scale_cur_y);
                    }

                    orig_x /= java.lang.Math.round(mScaleFactor);
                    orig_y /= java.lang.Math.round(mScaleFactor);

                    orig_x *= scale;
                    orig_y *= scale;

                    //mSelectionTaskManager.setOrigin((int) orig_x, (int) orig_y);
                    if(isSelectionToolEnabled)
                        MovementStack.add(new Pair((int)orig_x, (int)orig_y));

                    Log.e(Codistan_Tag, "Codistan Origins: " + String.valueOf(orig_x) + ", " + String.valueOf(orig_y));

                    break;
                case MotionEvent.ACTION_MOVE:
                    max_dist = dist * scale;

                    if (event.getAction() != 1) {
                        move_x = event.getX();
                        move_y = event.getY();

                        //Log.e(Codistan_Tag, "Move: " + String.valueOf(move_x) + ", " + String.valueOf(move_y));

                        move_x = (move_x - dest.left);
                        move_y = (move_y - dest.top);



                        if(java.lang.Math.round(mScaleFactor) > 2) {
                            move_x += (scale_cur_x * riz_scale);
                            move_y += (scale_cur_y * riz_scale);
                        } else {
                            move_x += (scale_cur_x);
                            move_y += (scale_cur_y);
                        }

                        move_x /= java.lang.Math.round(mScaleFactor);
                        move_y /= java.lang.Math.round(mScaleFactor);

                        move_x *= scale;
                        move_y *= scale;

                        Log.e(Codistan_Tag, "Codistan Move: " + String.valueOf(move_x) + ", " + String.valueOf(move_y));

                        if (move_x >= 0 && move_y >= 0) {
                            if (!isSelectionToolEnabled && isDistortionEnabled) {
                                warpPhotoFromC(image, height, width, max_dist/mScaleFactor, orig_x, orig_y, move_x, move_y);
                                first++;
                                distortedBmp.setPixels(image, 0, width, 0, 0, width, height);
                                fg = false;
                            } else {
                                //Cut Tool Enabled
                                distortedBmp.setPixels(image, 0, width, 0, 0, width, height);
                                MovementStack.add(new Pair((int) move_x, (int) move_y));

                            }
                        }
                    }
                    orig_x = move_x;
                    orig_y = move_y;
                    break;
                case MotionEvent.ACTION_UP:
                    if (isSelectionToolEnabled)
                        isDrawFinished = true;
                    break;
            }
        }
        v.invalidate();
    }
    return true;
}

注意:别忘了调用invalidate(),因为它将负责调用onDraw

可能的重复no m在屏幕快照上画一条线我看到了这一点但没有帮助可能的重复no m在屏幕快照上画一条线我看到了但没有帮助