init
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user