Aur*_*una 0 java image image-processing
我有一个问题,我无法弄清楚.我必须使用两个不同的图像处理技术:Skelethonization 和细化,我不得不这样做在Java中.现在的问题是我无法找到任何起点或教程.任何人都可以告诉我应该从哪里开始,或者有人可以解释我如何实现这一目标?我正在用Java编写应用程序BufferedImage,如果有可能的话,我想使用a (当然).
谢谢
您可以像这样绘制到BufferedImage:
public BufferedImage createSkelethonizationImage() {
BufferedImage image = new BufferedImage(width, height);
Graphics2D g2 = image.createGraphics();
// Perform your drawing here
g2.drawLine(...);
g2.dispose();
return image;
}
Run Code Online (Sandbox Code Playgroud)
要绘制图像,请创建一个扩展JComponent的新类并覆盖paint方法.以下是一些入门代码:
public class MyImage extends JComponent {
// Note: the image should be modified on the Event Dispatch Thread
private BufferedImage image = createSkelethonizationImage();
@Override
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑 - 完整解决方案:
public class Test {
public static void main(String[] args) {
// Width and height of your image
final int width = 200;
final int height = 200;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
MyImage image = new MyImage(width, height);
frame.add(image);
frame.setSize(new Dimension(width, height));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class MyImage extends JComponent {
// Note: image should be modified on the Event Dispatch Thread only
private final BufferedImage image;
public MyImage(int width, int height) {
image = createSkelethonizationImage(width, height);
setPreferredSize(new Dimension(width, height));
}
public BufferedImage createSkelethonizationImage(int width, int height) {
BufferedImage iamge = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = iamge.createGraphics();
// Perform your drawing here
g2.setColor(Color.BLACK);
g2.drawLine(0, 0, 200, 200);
g2.dispose();
return iamge;
}
@Override
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1433 次 |
| 最近记录: |