Skip to content

Commit cc2142b

Browse files
lor6pivovarit
authored andcommitted
twelvemonkeys example (eugenp#1903)
1 parent 14aea0f commit cc2142b

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

image-processing/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
<groupId>commons-logging</groupId>
4141
</exclusion>
4242
</exclusions>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.twelvemonkeys.imageio</groupId>
46+
<artifactId>imageio-core</artifactId>
47+
<version>3.3.2</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.twelvemonkeys.imageio</groupId>
51+
<artifactId>imageio-bmp</artifactId>
52+
<version>3.3.2</version>
4353
</dependency>
4454
</dependencies>
4555

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.imageprocessing.twelvemonkeys;
2+
3+
import java.awt.BasicStroke;
4+
import java.awt.Color;
5+
import java.awt.Dimension;
6+
import java.awt.Graphics2D;
7+
import java.awt.image.BufferedImage;
8+
import java.io.File;
9+
import java.io.IOException;
10+
11+
import javax.imageio.ImageIO;
12+
import javax.swing.ImageIcon;
13+
import javax.swing.JFrame;
14+
import javax.swing.JLabel;
15+
import javax.swing.JPanel;
16+
17+
public class TwelveMonkeysExample {
18+
public static void main(String[] args) throws IOException {
19+
BufferedImage image = loadImage();
20+
drawRectangle(image);
21+
displayImage(image);
22+
}
23+
24+
private static BufferedImage loadImage() throws IOException {
25+
String imagePath = TwelveMonkeysExample.class.getClassLoader().getResource("Penguin.ico").getPath();
26+
return ImageIO.read(new File(imagePath));
27+
}
28+
29+
private static void drawRectangle(BufferedImage image) {
30+
Graphics2D g = (Graphics2D) image.getGraphics();
31+
g.setStroke(new BasicStroke(3));
32+
g.setColor(Color.BLUE);
33+
g.drawRect(10, 10, image.getWidth() - 20, image.getHeight() - 20);
34+
}
35+
36+
private static void displayImage(BufferedImage image) {
37+
JLabel picLabel = new JLabel(new ImageIcon(image));
38+
39+
JPanel jPanel = new JPanel();
40+
jPanel.add(picLabel);
41+
42+
JFrame f = new JFrame();
43+
f.setSize(new Dimension(200, 200));
44+
f.add(jPanel);
45+
f.setVisible(true);
46+
}
47+
}
164 KB
Binary file not shown.

0 commit comments

Comments
 (0)