# 根据坐标点画图

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class DrawTest {

	public static void main(String[] args) throws IOException {
		// 智能笔轨迹坐标点
		List<String> points = FileUtils.readLines(new File("C:\\Users\\leichu\\Desktop\\1.txt"), StandardCharsets.UTF_8);
		//从本地读取图片作为底图
		String path = "C:\\Users\\leichu\\Desktop\\1.png";
		BufferedImage backImage = ImageIO.read(new File(path));
		final int width = backImage.getWidth();
		final int height = backImage.getHeight();
		// 生产画板
		Graphics2D graphics = (Graphics2D) backImage.getGraphics();
		// 抗锯齿
		graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);//去文字锯齿
		graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //去图片锯齿
		graphics.setColor(Color.BLUE);
		Stroke stroke = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1.0F, null, 1.0F);
		graphics.setStroke(stroke);
		for (String point : points) {
			final JSONObject jsonObject = JSONObject.parseObject(point);
			final Integer x = jsonObject.getInteger("x");
			final Integer y = jsonObject.getInteger("y");
			System.out.println(point);
			graphics.drawLine(x, y, x, y);
		}
		graphics.drawImage(backImage, width, height, width, height, null);
		graphics.dispose();
		String resultPath = "C:\\Users\\leichu\\Desktop\\2.png";
		ImageIO.write(backImage, "PNG", new File(resultPath));
	}

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

坐标点数据样例:

{x: 33.08102184722437, y: 43.51141866099474}
{x: 32.83414854985703, y: 43.758291958362086}
{x: 32.648993576831515, y: 43.88172860704576}
{x: 32.58727525248969, y: 43.9434469313876}
{x: 32.46383860380601, y: 44.00516525572943}
{x: 32.46383860380601, y: 44.06688358007127}
{x: 32.40212027946417, y: 44.1286019044131}
{x: 32.46383860380601, y: 44.06688358007127}
{x: 32.52555692814785, y: 44.06688358007127}
{x: 32.58727525248969, y: 44.06688358007127}
{x: 32.71071190117335, y: 43.9434469313876}
{x: 32.957585198540706, y: 43.820010282703926}
{x: 33.32789514459172, y: 43.573136985336575}
{x: 33.75992341498458, y: 43.32626368796923}
{x: 34.43882498274478, y: 43.01767206626005}
{x: 35.30288152353049, y: 42.64736212020903}
{x: 36.1669380643162, y: 42.33877049849985}
{x: 36.90755795641824, y: 42.030178876790664}
{x: 37.77161449720395, y: 41.78330557942332}
{x: 38.882544335357004, y: 41.47471395771414}
{x: 40.116910822193745, y: 41.22784066034679}
{x: 41.10440401166312, y: 41.04268568732128}
{x: 42.03017887679067, y: 40.91924903863761}
{x: 42.955953741918215, y: 40.91924903863761}
{x: 43.696573634020254, y: 40.91924903863761}
{x: 44.37547520178046, y: 41.104404011663114}
{x: 44.86922179651515, y: 41.289558984688625}
{x: 45.23953174256617, y: 41.53643228205597}
{x: 45.67156001295902, y: 42.091897201132504}
{x: 45.85671498598453, y: 42.58564379586719}
{x: 45.98015163466821, y: 43.32626368796923}
{x: 45.98015163466821, y: 44.19032022875494}
{x: 45.91843331032637, y: 45.11609509388249}
{x: 45.67156001295902, y: 46.16530660769371}
{x: 45.36296839124984, y: 47.152799797163105}
{x: 44.86922179651515, y: 48.325447959657986}
{x: 44.19032022875495, y: 49.62153277083655}
{x: 43.51141866099475, y: 50.794180933331454}
{x: 42.64736212020904, y: 52.15198406885186}
{x: 41.72158725508149, y: 53.44806888003042}
{x: 40.79581238995394, y: 54.49728039384165}
{x: 39.808319200484554, y: 55.29961861028552}
{x: 38.82082601101517, y: 55.85508352936205}
{x: 37.70989617286211, y: 56.53398509712225}
{x: 36.8458396320764, y: 57.027731691856935}
{x: 36.29037471299987, y: 57.27460498922428}
{x: 35.920064766948855, y: 57.39804163790795}
{x: 35.673191469581504, y: 57.4597599622498}
{x: 35.673191469581504, y: 57.58319661093347}
{x: 35.673191469581504, y: 57.52147828659162}
{x: 35.73490979392334, y: 57.52147828659162}
{x: 35.73490979392334, y: 57.52147828659162}
{x: 35.85834644260702, y: 57.52147828659162}
{x: 36.04350141563253, y: 57.4597599622498}
{x: 36.41381136168354, y: 57.336323313566126}
{x: 37.03099460510191, y: 57.15116834054061}
{x: 37.70989617286211, y: 56.966013367515096}
{x: 38.63567103798966, y: 56.7808583944896}
{x: 39.49972757877537, y: 56.65742174580593}
{x: 40.42550244390292, y: 56.59570342146408}
{x: 41.41299563337231, y: 56.53398509712225}
{x: 42.33877049849985, y: 56.59570342146408}
{x: 43.2645453636274, y: 56.71914007014775}
{x: 43.881728607045766, y: 56.90429504317327}
{x: 44.498911850464125, y: 57.336323313566126}
{x: 45.05437676954066, y: 57.768351583958975}
{x: 45.548123364275355, y: 58.3238165030355}
{x: 46.103588283351876, y: 59.12615471947937}
{x: 46.35046158071923, y: 59.80505628723957}
{x: 46.6590532024284, y: 60.915986125392635}
{x: 46.844208175453915, y: 62.15035261222936}
{x: 46.96764482413759, y: 63.323000774724264}
{x: 47.029363148479426, y: 64.49564893721916}
{x: 46.844208175453915, y: 65.79173374839772}
{x: 46.53561655374473, y: 67.2729735326018}
{x: 46.227024932035555, y: 68.63077666812221}
{x: 45.91843331032637, y: 69.74170650627525}
{x: 45.548123364275355, y: 70.91435466877016}
{x: 45.05437676954066, y: 72.02528450692321}
{x: 44.622348499147805, y: 73.07449602073443}
{x: 44.19032022875495, y: 73.8768342371783}
{x: 43.634855309678414, y: 74.67917245362219}
{x: 42.83251709323454, y: 75.60494731874972}
{x: 41.90674222810699, y: 76.34556721085177}
{x: 40.672375741270265, y: 77.20962375163747}
{x: 39.19113595706619, y: 77.95024364373951}
{x: 37.70989617286211, y: 78.32055358979053}
{x: 35.85834644260702, y: 78.2588352654487}
{x: 33.75992341498458, y: 78.13539861676503}
{x: 31.784937036045807, y: 77.95024364373951}
{x: 29.995105630132546, y: 77.88852531939767}
{x: 28.266992548561127, y: 77.95024364373951}
{x: 26.477161142647862, y: 77.82680699505585}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
更新时间: 2021-09-17 11:17:06