init
This commit is contained in:
parent
43f407e6e7
commit
b6e8cf95c7
19
imageprocessing/pom.xml
Normal file
19
imageprocessing/pom.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>imageprocessing</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.imagej</groupId>
|
||||
<artifactId>ij</artifactId>
|
||||
<version>1.51h</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
22
imageprocessing/src/main/java/imagej/DrawRect.java
Normal file
22
imageprocessing/src/main/java/imagej/DrawRect.java
Normal file
@ -0,0 +1,22 @@
|
||||
package imagej;
|
||||
|
||||
import ij.IJ;
|
||||
import ij.ImagePlus;
|
||||
import ij.process.ImageProcessor;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawRect {
|
||||
public static void main(String[] args) {
|
||||
ImagePlus imp = IJ.openImage(DrawRect.class.getClassLoader().getResource("lena.jpg").getPath());
|
||||
drawRect(imp);
|
||||
imp.show();
|
||||
}
|
||||
|
||||
private static void drawRect(ImagePlus imp) {
|
||||
ImageProcessor ip = imp.getProcessor();
|
||||
ip.setColor(Color.BLUE);
|
||||
ip.setLineWidth(4);
|
||||
ip.drawRect(10, 10, imp.getWidth() - 20, imp.getHeight() - 20);
|
||||
}
|
||||
}
|
40
imageprocessing/src/main/java/swing/DrawRect.java
Normal file
40
imageprocessing/src/main/java/swing/DrawRect.java
Normal file
@ -0,0 +1,40 @@
|
||||
package swing;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DrawRect {
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedImage image = loadImage();
|
||||
drawRectangle(image);
|
||||
displayImage(image);
|
||||
}
|
||||
|
||||
private static BufferedImage loadImage() throws IOException {
|
||||
String imagePath = DrawRect.class.getClassLoader().getResource("lena.jpg").getPath();
|
||||
return ImageIO.read(new File(imagePath));
|
||||
}
|
||||
|
||||
private static void drawRectangle(BufferedImage image) {
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
g.setStroke(new BasicStroke(3));
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawRect(10, 10, image.getWidth() - 20, image.getHeight() - 20);
|
||||
}
|
||||
|
||||
private static void displayImage(BufferedImage image) {
|
||||
JLabel picLabel = new JLabel(new ImageIcon(image));
|
||||
|
||||
JPanel jPanel = new JPanel();
|
||||
jPanel.add(picLabel);
|
||||
|
||||
JFrame f = new JFrame();
|
||||
f.setSize(new Dimension(image.getWidth(), image.getHeight()));
|
||||
f.add(jPanel);
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
BIN
imageprocessing/src/main/resources/lena.jpg
Normal file
BIN
imageprocessing/src/main/resources/lena.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 93 KiB |
Loading…
x
Reference in New Issue
Block a user