Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can draw to the BufferedImage like this:</p> <pre><code>public BufferedImage createSkelethonizationImage() { BufferedImage image = new BufferedImage(width, height); Graphics2D g2 = image.createGraphics(); // Perform your drawing here g2.drawLine(...); g2.dispose(); return image; } </code></pre> <p>To draw the image, create a new class that extends JComponent and overrides the paint method. Here is some code to get started:</p> <pre><code>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); } } </code></pre> <p>Edit - Complete solution:</p> <pre><code>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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload