Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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
使用Java在Android中使用线条函数绘图_Java_Android_Drawing - Fatal编程技术网

使用Java在Android中使用线条函数绘图

使用Java在Android中使用线条函数绘图,java,android,drawing,Java,Android,Drawing,好的,我有一个服务器(在计算机上)和一个客户端(安卓手机) 我已经通过套接字建立了连接,我可以在服务器框架上画图,然后在客户端屏幕上显示它 这就是我要发送的内容: addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { // save coord x,y when mouse is pressed startDrawing=tru

好的,我有一个服务器(在计算机上)和一个客户端(安卓手机)

我已经通过套接字建立了连接,我可以在服务器框架上画图,然后在客户端屏幕上显示它

这就是我要发送的内容:

 addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            // save coord x,y when mouse is pressed
            startDrawing=true;
            oldX = e.getX();
            oldY = e.getY();
            try {
                if (s != null) {
                    mouseSend = new MouseData(oldX, oldY, currentX, currentY, startDrawing, isDrawing, endDrawing);
                    out.writeObject(mouseSend);
                }
            }
            catch (IOException ex){
                ex.printStackTrace();
            }



        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            // coord x,y when drag mouse
            currentX = e.getX();
            currentY = e.getY();
            isDrawing = true;
            startDrawing=false;
            endDrawing=false;

            if (g2 != null) {
                try {
                    // draw line if g2 context not null
                    g2.drawLine(oldX, oldY, currentX, currentY);
                    if(s!=null) {
                        mouseSend = new MouseData(oldX, oldY, currentX, currentY, startDrawing, isDrawing, endDrawing);
                        out.writeObject(mouseSend);
                    }
                    // refresh draw area to repaint
                    repaint();
                    // store current coords x,y as olds x,y
                    oldX = currentX;
                    oldY = currentY;
                }
                catch (IOException ex) {
                    Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });
以下是我从客户机上收到的信息,并使用这些数据来画线:

socket = new Socket("192.168.20.7",8080);
            out = new ObjectOutputStream(socket.getOutputStream());
            in = new ObjectInputStream(socket.getInputStream());


            while(in!=null) {

                mouseReceive = (MouseData) in.readObject();
                xReceive = mouseReceive.mouseX;
                yReceive = mouseReceive.mouseY;
                xNew = mouseReceive._nowX;
                yNew = mouseReceive._nowY;
                startDrawing = mouseReceive.startDrawing;
                isDrawing = mouseReceive.isDrawing;
                endDrawing = mouseReceive.endDrawing;

            }
和绘图功能:

    public void drawPath() {


invalidate();

    if(startDrawing=true){
        testx=xReceive;
        testy=yReceive;
    }

    if(isDrawing=true) {
        drawCanvas.drawLine(testx, testy, xNew, yNew, drawPaint);
        invalidate();


        System.out.println(xReceive + " " + yReceive + " " + xNew + " " + yNew);
    }

    invalidate();
}
现在问题来了。我想让它在服务器上的人正在绘制的任何地方绘制一条路径,我正在尝试使用线条来完成。但现在它正在创建点,而没有正确地连接它们。 我试过很多方法,也试过使用画布上的路径,但我什么都做不到:(

这开始令人沮丧,所以我想我会到这里寻求帮助

我曾想过通过数组列表将它们连接起来,并在点之间创建线,但我不知道从何处开始:/

如果有人能帮我,我会非常感激的

下面是一张它看起来像什么的图片:


怎么办?我以前没有使用过样条曲线,与我试图实现的功能相比,它看起来有点高级:如果我用public void drawPath(){invalidate();if(isDrawing=true){drawCanvas.drawLine(testx,testy,xNew,yNew,drawPaint);testx=xNew;testy=yNew;invalidate();System.out.println(xReceive+“”+yReceive+“”+xNew+“”+yNew);}invalidate();}它可以正常工作。它很平滑,没有漏洞,但这里的问题是它是一条连续的路径,我无法停止它或开始新的:(如图所示:您是否从UI线程调用drawPath(),并在另一个线程上调用网络通信?不,它们在同一个类中。我对线程没有太多了解,并且我怀疑我是否应该使用它。我在公共类MyClientTask中调用我的网络通信{@Override protected Void doInBackground(Void…params){这可能也是错误的