本文介绍了在屏幕上的Andr​​oid图形对象和获取几何数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对图形对象的任何经验,例如顶点多边形并获得其表面和周长。

Has anybody experience on drawing objects, by vertices e.g. Polygons and obtaining their surface and perimeter.

几何将通过手工使用顶点绘制坐标或类似的然后形状形成。我需要获得这些封闭形状的表面。

The geometry will be drawn by hand using vertices or coordinates similar to https://play.google.com/store/apps/details?id=de.hms.xconstruction and then shapes formed. I need to obtain the surface of these closed shapes.

有没有在网络上任何可用的例子吗?

Is there any available example on the net?

先谢谢了。

推荐答案

我觉得以下code的一块可能是一个良好的开端。它基本上把一切用户触摸的行:

I think the following piece of code could be a good start. It basically draws lines between all user touches:

public class TestActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new DrawingView(this));
}

class DrawingView extends SurfaceView {

    private final SurfaceHolder surfaceHolder;
    private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    private List<Point> pointsList = new ArrayList<Point>();

    public DrawingView(Context context) {
        super(context);
        surfaceHolder = getHolder();
        paint.setColor(Color.WHITE);
        paint.setStyle(Style.FILL);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (surfaceHolder.getSurface().isValid()) {

                // Add current touch position to the list of points
                pointsList.add(new Point((int)event.getX(), (int)event.getY()));

                // Get canvas from surface
                Canvas canvas = surfaceHolder.lockCanvas();

                // Clear screen
                canvas.drawColor(Color.BLACK);

                // Iterate on the list
                for(int i=0; i<pointsList.size(); i++) {
                    Point current = pointsList.get(i);

                    // Draw points
                    canvas.drawCircle(current.x, current.y, 10, paint);

                    // Draw line with next point (if it exists)
                    if(i + 1 < pointsList.size()) {
                        Point next = pointsList.get(i+1);
                        canvas.drawLine(current.x, current.y, next.x, next.y, paint);
                    }
                }

                // Release canvas
                surfaceHolder.unlockCanvasAndPost(canvas);
            }
        }
        return false;
    }

}

这篇关于在屏幕上的Andr​​oid图形对象和获取几何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 21:59