Java Image Editor which renders output as source code?
Asked Answered
C

3

6

Alex explained what I'm looking for much better than I have:

You want an existing program that allows you to draw a picture, captures what you do as you draw, and writes each action as a Java command. When you click the "Drawl Oval" tool and click at 0,0 and then at 50,50, it would generate the line g.drawOval(0,0,50,50).

If anybody knows of a program such as this, let me know. Thanks.


Original question:

I've been working with Java and custom drawing using the java.awt.Graphics library lately, but find it is taking too much time to write manually. Is there any simple graphics editor (like mspaint) which generates source code?

Example:

Drawing this: alt text

Would generate:

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

Thanks.

Cobos answered 13/7, 2009 at 16:13 Comment(6)
I didn't understand your example. Your drawing shows a circle with two tangents at right angles, but you want that to generate commands to draw a rectangle. How come?Trunkfish
I believe that he wants an app like XamlPadX for WPF, ie, that he draws a shape (maybe in illustrator?), and then that shape gets translated into code.Linsk
I understand the principle, I just didn't get the specific example he gave.Trunkfish
Can you be a bit more specific? Adobe Illustrator generates EPS files. Since PostScript is a programming language, then you can say that Illustrator generates source code.Position
I'm still a bit baffled as to why the SVG to Java2D transcoder doesn't supply what you need. Its not real time, but it should be really easy to write a batch file to generate it for you.Woollyheaded
A SVG to Java2D converter is nice, but not what I'm looking for.Cobos
W
14

If they are vectors, you could use an SVG Editor (eg, Inkscape) along with Kirill's SVG to Java2D Transcoder to simplify this. It isn't perfect, but Kirill is very responsive in responding to requests for enhancement.

Woollyheaded answered 13/7, 2009 at 16:25 Comment(0)
T
3

It's unclear what you are asking. Two guesses:

  1. You want an existing program that allows you to draw a picture, captures what you do as you draw, and writes each action as a Java command. When you click the "Drawl Oval" tool and click at 0,0 and then at 50,50, it would generate the line g.drawOval(0,0,50,50).

    I do not know of any such tool. But the above might help you reword your question so that others can share their knowledge.

  2. You want a program that takes an existing bitmap and converts it into a series of commands that will replicate the bitmap. Other than simply outputting pixels, such a tool is nearly impossible to write; attempting to decompose an arbitrary picture into simple drawing commands is very hard.

    In this case, I would recommend simply importing the bitmap as a JPG, PNG, whatever, and using drawImage() instead of using Graphics calls.

Tertiary answered 27/7, 2009 at 19:20 Comment(0)
D
0

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

In a sense XPM image converters are source code generators and translators. You are looking for something similar to output Java AWT, but for many real images or photographs it would be complicated to do analysis on the image to find oval,etc and create the code for drawing them with lines and shapes (well unless the image had filters applied to simplify it, or was an SVG as someone pointed out). It would probably have to convert to a bitmap of some form and keep it in an array in the generated Java source.

Depurate answered 25/7, 2009 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.