2

I'm stuck trying to convert an array of points which represent a drawing(simple 2D black lines) taken from a mobile phone. I pass that array of points to a server which then emails that drawing to another person.

I can't find a way to convert that array of points to an image, png, or something else. And then upload it to an static server so I can insert it in an email and send to the other person.

I'm looking something like canvas on android but on the serverside so I can output an image. Preferably Java, but at this point I would take anything.

An ex of the array of points:

        {
            "drawing_objects": [
                [
                    {
                        "x": 177,
                        "y": 246
                    },
                    {
                        "x": 177,
                        "y": 246
                    },
                    {
                        "x": 177,
                        "y": 246
                    }
                ],
                [
                    {
                        "x": 870,
                        "y": 298
                    },
                    {
                        "x": 866.5316,
                        "y": 302.62445
                    }
                ]
            ]
        }

These are two lines, in a drawing, the first with 3 point, the second one with 2.

maty_nz
  • 280
  • 2
  • 4
  • 16
  • Is your server Java based? – Abdul Fatir May 29 '14 at 19:17
  • [There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow down the answer set or to isolate an issue that can be answered in a few paragraphs.](http://stackoverflow.com/help/closed-questions) – durron597 May 29 '14 at 19:19
  • I have a server Java based but I can also use a python, node or ruby server as well I'm not interested in a particular language – maty_nz May 29 '14 at 19:24

1 Answers1

3

If you are using a Java based server, then you could create a Graphics2D, draw the points and then export that to PNG or whatever you want.

import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

//…

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

Graphics2D ig2 = bi.createGraphics();
//Draw some lines to the graphic
ig2.drawLine(x1,y1,x2,y2);
ig2.drawLine(x2,y2,x3,y3);
//...

//Export the result to a file
ImageIO.write(bi, "PNG", new File(“c:\\name.png”));
jgyonzo
  • 46
  • 2
  • Nice answer, thanks. I just had a little problem with drawline because it takes integer and I needed Double so I used Line2D `ig2.draw(new Line2D.Double(x1,y1,x2,y2))` – maty_nz May 31 '14 at 02:19