绘制路径变焦和DARG [英] Draw Path with zoom and darg

查看:238
本文介绍了绘制路径变焦和DARG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

M发展中,我粘贴的图片,做绘画在画布上的应用程序。这个应用程序还可以放大/缩小画布或将其拖动到不同的位置。我的问题是:我不能让缩放或拖动画布后正确的画布坐标。我想画手指画在画布上进行缩放或拖动,但无法检索在那里我已经碰到了合适的位置后...

'm developing an application in which I'm pasting images, doing drawing and painting on canvas. This app can also Scale up/down the canvas or drag it to different location. My problem is: I can't get the correct canvas coordinates after scaling or dragging the canvas. I want to draw finger paint after the canvas is scaled or dragged but unable to retrieve the right place where i've touched...

@Override
public boolean onTouchEvent(MotionEvent event) {

    scaleListener.onTouchEvent(event);

    synchronized(thread.getSurfaceHolder()){

        switch ( event.getAction() & MotionEvent.ACTION_MASK ){

            case MotionEvent.ACTION_DOWN :
                // Remember our initial down event location.
                savedMatrix.set(m_matrix);
                start.set(event.getX() , event.getY());
                mode = DRAG;                
            break;

            case MotionEvent.ACTION_POINTER_DOWN :

                oldDist = spacing(event);
                if (oldDist > 10f) {

                    savedMatrix.set(m_matrix);
                    m_matrix.getValues(matrixValues);
                    midPoint(mid, event);
                    mode = ZOOM;
                }

             break;

            case MotionEvent.ACTION_UP :
            case MotionEvent.ACTION_POINTER_UP :
                    mode = NONE;

            break;

            case MotionEvent.ACTION_MOVE :

                if(mode==DRAG && isDragAllowd){
                        m_matrix.set(savedMatrix);
                        rebound(event.getX() , event.getY());
                }
                else if(mode==ZOOM){

                    float newDist = spacing(event);
                    if (newDist > 10f){

                            m_matrix.set(savedMatrix);

                            float scale = newDist/oldDist;
                            m_matrix.getValues(matrixValues);
                            float currentScale = matrixValues[Matrix.MSCALE_X];

                            // limit zoom
                            if (scale * currentScale > maxZoom){
                                    scale = maxZoom / currentScale;
                                    //scale = maxZoom;
                            }
                            else if (scale * currentScale < minZoom){
                                    scale = minZoom / currentScale;
                                    //scale = minZoom;
                            }

                            m_matrix.postScale(scale, scale, mid.x, mid.y);
                            m_matrix.getValues(matrixValues);

                  }

            }
       break;

    }

    return true; //done with this event so consume it


    }       

}

@Override
protected void onDraw(Canvas canvas){
    super.onDraw(canvas);

            canvas.drawColor(Color.WHITE);
        canvas.drawBitmap(currentBitmap, m_matrix, null);
        c2.drawColor(Color.BLACK); 
        commandManager.executeAll(c2); // Drawing all the Paints on Canvas c2
        // Overlay bitmap it's a transparent layour 
            canvas.drawBitmap(overlayBitmap, 0, 0, pTouch);

}

当用户放大位图他是不是能画过它,放大绘制在适当的地方不会发生了。

when user zoom the bitmap he is not able to draw over it , after zooming drawing doesn't happen at proper place.

推荐答案

使用下列公式转化为积分,之后变焦过程中或滚动后该用户将不会面临任何困难绘画。

use the following equation for transformed the points, after that user will not face an any difficulty painting during zoom or after scrolling.

 float f1 = (( motionEvent.getX() - m_transformedPoints[0] )/( m_transformedPoints[2] - m_transformedPoints[0] ))*currentBitmapWidth;
     float f2 = (( motionEvent.getY() - m_transformedPoints[1] )/( m_transformedPoints[3] - m_transformedPoints[1] ))*currentBitmapHeight; 

    //calculate the transformed view in onDraw Method
    this.m_transformedPoints[0] = 0.0F;
    this.m_transformedPoints[1] = 0.0F;
    this.m_transformedPoints[2] = currentBitmapWidth;
    this.m_transformedPoints[3] = currentBitmapHeight;
    this.m_matrix.mapPoints(this.m_transformedPoints);

这篇关于绘制路径变焦和DARG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆