-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImagePanel.java
69 lines (51 loc) · 1.92 KB
/
ImagePanel.java
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
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class ImagePanel extends JPanel{
public BufferedImage image;
public Graphics imageGraphics;
public GUI gui;
public BufferedImage pathimage;
public BufferedImage rectimage;
public int size;
public double halfsize;
// public Graphics imageGraphics;
public ImagePanel() {
size = 500;
setSize(size,size);
image = new BufferedImage(size,size,BufferedImage.TYPE_3BYTE_BGR);
pathimage= new BufferedImage(size,size,BufferedImage.TYPE_4BYTE_ABGR);
imageGraphics = image.getGraphics();
imageGraphics.setColor(Color.WHITE);
imageGraphics.drawRect(0,0,size,size);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, null);
if(gui!= null ) {
if(gui.renderPath) {
g.drawImage(pathimage, 0, 0, null);
}
if(gui.renderRect) {
g.setColor(Color.cyan);
g.drawLine(gui.firstmousedragx, gui.firstmousedragy, gui.firstmousedragx, gui.mousedragy );
g.drawLine(gui.firstmousedragx,gui.firstmousedragy,gui.mousedragx,gui.firstmousedragy);
g.drawLine(gui.mousedragx,gui.firstmousedragy,gui.mousedragx,gui.mousedragy);
g.drawLine(gui.firstmousedragx,gui.mousedragy,gui.mousedragx,gui.mousedragy);
}
}
}
public void remakePathImage() {
halfsize = size/2f;
pathimage= new BufferedImage(size,size,BufferedImage.TYPE_4BYTE_ABGR);
}
public void remakeImage() {
halfsize = size/2f;
setSize(size,size);
image = new BufferedImage(size,size,BufferedImage.TYPE_3BYTE_BGR);
imageGraphics = image.getGraphics();
imageGraphics.setColor(Color.WHITE);
imageGraphics.drawRect(0,0,size,size);
}
}