Java image editor that displays output as source code?

Alex explained that I am looking much better than mine:

You need an existing program that allows you to draw an image, captures what you do when you draw, and record each action as a Java command. when you click on the "Drawl Oval" tool and click on 0,0 and then on 50.50, this will generate the g.drawOval line (0, 0.50, 50).

If anyone knows about such a program, let me know. Thanks.


The original question:

Recently, I have been working with Java and custom drawing using the java.awt.Graphics library, but I find it takes too much time to write manually. Is there a simple graphical editor (e.g. mspaint) that generates source code?

Example:

Drawing: alt text

Generates:

public void update(Graphics g) { g.translate(0, 0); g.drawOval(0, 0, 50, 50); } 

Thanks.

+6
java code-generation graphics
source share
3 answers

If these are vectors, you can use an SVG editor (e.g. Inkscape), as well as Cyril SVG for Java2D Transcoder to simplify this. This is not ideal, but Cyril is very sensitive to requests for improvement.

+14
source share

It is not clear what you are asking. Two guesses:

  • You want your existing program to allow you to draw an image, captures what you do when you draw, and writes each action as a Java command. When you click on the "Drawl Oval" tool and click on 0,0, and then on 50.50, it will generate the string g.drawOval(0,0,50,50) .

    I do not know such a tool. But the above can help you reformulate your question so that others can share their knowledge.

  • You need a program that accepts an existing bitmap and converts it into a series of commands that will replicate the bitmap. Besides simple pixel output, such a tool is almost impossible to record; trying to decompose an arbitrary image into simple drawing commands is very difficult.

    In this case, I would recommend just importing the bitmap as JPG, PNG, etc. using drawImage () instead of using image calls.

+3
source share

Not what you were looking for, I should mention that the XPM (X Pixmap) format is basically a subset of the C programming language. XPM2 simplified it by removing the syntax attributes of C. XPM3 brought them back.

In a sense, XPM image converters are source code generators and translators. You are looking for something similar to the Java AWT output, but for many real images or photographs it would be difficult to do an analysis on the image to find an oval, etc., and create code to draw them with lines and shapes (well, if the image there were no filters used to simplify it, or SVG, as someone pointed out). It probably would have to convert to a bitmap of some shape and store it in an array in the generated Java source.

0
source share