2

我被困在尝试转换代表从手机拍摄的绘图(简单的 2D 黑线)的点数组。我将该点数组传递给服务器,然后将该图形通过电子邮件发送给另一个人。

我找不到将点数组转换为图像、png 或其他内容的方法。然后将其上传到静态服务器,以便我可以将其插入电子邮件并发送给其他人。

我在 android 上看起来像画布,但在服务器端,所以我可以输出图像。最好是 Java,但在这一点上,我什么都愿意。

点数组的一个 ex:

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

这是两条线,在一张图中,第一条是 3 点,第二条是 2 点。

4

1 回答 1

3

如果您使用的是基于 Java 的服务器,那么您可以创建一个 Graphics2D,绘制点,然后将其导出为 PNG 或任何您想要的。

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”));
于 2014-05-29T20:43:37.190 回答