Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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 在画布绘图中,如何移动由路径创建的ShapeDrawble对象?_Android - Fatal编程技术网

Android 在画布绘图中,如何移动由路径创建的ShapeDrawble对象?

Android 在画布绘图中,如何移动由路径创建的ShapeDrawble对象?,android,Android,在画布绘制中,如何有效地移动由路径创建的形状可拖动对象 下面的代码似乎是通过新的路径移动的,所以每次都要重新创建可变形的对象。这是非常浪费资源的,有什么办法解决吗 private void drawBitmapShape(Canvas canvas, Paint paint) { /*Draw a hollow triangle*/ Path path=new Path(); path.moveTo(10, 330); p

在画布绘制中,如何有效地移动由路径创建的形状可拖动对象

下面的代码似乎是通过新的路径移动的,所以每次都要重新创建可变形的对象。这是非常浪费资源的,有什么办法解决吗

private void drawBitmapShape(Canvas canvas, Paint paint)
    {
         /*Draw a hollow triangle*/
        Path path=new Path();
        path.moveTo(10, 330);
        path.lineTo(70,330);
        path.lineTo(40,270);
        path.close();
        //canvas.drawPath(path, paint);

        /* create ShapeDrawable object and define the shape is elliptic */
        mShape = new ShapeDrawable(new PathShape(path, BitQQheight, BitQQheight));

        /* set up the ellipse things to draw for ShapeDrawable pictures */
        mShape.getPaint().setShader(mBitmapShader);
        /*set display area*/
        //BitQQheight=BitQQheight*2;
        mShape.setBounds(0,0, BitQQwidth, BitQQheight);

        /* draw ShapeDrawableQQ */
        mShape.draw(canvas);
    }
我想我已经解决了

private void drawBitmapShape(Canvas canvas, Paint paint)
    {
        canvas.save();
        canvas.translate(5, 5);
        // rotate
        //canvas.rotate(90, 60, 310);
         /*Draw a hollow triangle*/
        Path path=new Path();
        path.moveTo(10, 330);
        path.lineTo(70,330);
        path.lineTo(40,270);
        path.close();
        //canvas.drawPath(path, paint);

        /* create ShapeDrawable object and define the shape is elliptic */
        mShape = new ShapeDrawable(new PathShape(path, BitQQheight, BitQQheight));

        /* set up the ellipse things to draw for ShapeDrawable pictures */
        mShape.getPaint().setShader(mBitmapShader);
        /* set display area */
        //BitQQheight=BitQQheight*2;
        mShape.setBounds(0,0, BitQQwidth, BitQQheight);

        /* draw ShapeDrawableQQ */
        mShape.draw(canvas);
        canvas.restore();
    }