Alceu Costa
Alceu Costa

Reputation: 9889

Is there a Java library for writing a drawing program?

I need to write a simple Java GUI application that, basically, allows the user to mark regions in a CT lung image.

To make the marking process easier, it is important that the program provides some basic tools/functionalities similar to a drawing program like MS Paint, like, for example, undo/redo, marker (brush) width and region fill.

Is there any Java library that provides components to write a drawing program?

Upvotes: 12

Views: 4868

Answers (4)

Kyle
Kyle

Reputation: 3885

Check out gef and draw 2d from eclipse. Draw2D provides the ability to render graphics on top of swt. GEF provides an MVC framework as well as a command framework for undo/redo. There is a learning curve, but GEF is really powerful.

Upvotes: 1

Ollie Glass
Ollie Glass

Reputation: 19993

Processing lets you draw shapes, set line thickness and colors, display images and perform many other drawing functions in Java. It can be used it as a Java library and integrated into a Swing app.

Here's some sample Processing code:

void setup() {
  size(400, 400);  // set window size to 400 x 400 pixels
  PImage lungImg = loadImage("https://i.sstatic.net/gwyp0.jpg");
  image(lungImg, 0, 0);
}

void draw() {
}

void mousePressed() {
  noFill();          // no fill color for the circle
  stroke(255, 0, 0); // set pen color to red
  strokeWeight(5);   // set line thickness to 5 pixels

  // draw ellipse at mouse position, 50 pixels height & width (i.e. a circle)
  ellipse(mouseX, mouseY, 50, 50); 
}

This will run on its own in the Processing IDE, which also adds some syntactic sugar. It is 'real' Java underneath; the methods in the above code can be found in the PApplet class.

Clicking places a red circle. Here's the resulting app:

enter image description here

Upvotes: 7

Favonius
Favonius

Reputation: 13974

I will suggest you to have a look at ImageJ. The big plus point is its root in medical domain and it is extensible through custom plug-in. The following parts taken from ImageJ Wikipedia entry.

ImageJ is a public domain, Java-based image processing program developed at the National Institutes of Health. ImageJ was designed with an open architecture that provides extensibility via Java plugins and recordable macros.

And if you don't find a functionality as per your needs than it allows you to write your own plug-in.

User-written plugins make it possible to solve many image processing and analysis problems, from three-dimensional live-cell imaging, to radiological image processing, multiple imaging system data comparisons to automated hematology systems.

The only problem that I can foresee is the amount of extra things that you have to ship along with the functionality you want to implement.

If you want to avoid the above problem then have a look at @Zack's answer. In addition to that have a look at these:

  1. Flood fill using a stack
  2. Add an undo/redo function to your Java apps with Swing
  3. Java 2D Samples - Java2s

Upvotes: 10

Zack Marrapese
Zack Marrapese

Reputation: 12080

If you are looking to do a desktop app, you will probably use Swing.

For drawing on a canvas in particular, see the Java 2D API.

Undo/redo can be handled using the Command design pattern.

Upvotes: 2

Related Questions