Java 2d graphic library - java

Hi I am trying to create simple 2d graphic editor. I need some library which will create shape from given points(draw lines between these points) and then user can move this shape with mouse or scale this shape with mouse. I need points, because I have Oracle Jgeometry shape saved in database and I need to visualize it. Could you please help me?
I found jGraph but I don't know, how to create shape from points, or get these points from shape

Instead of reinventing the wheel I would suggest using svg. There is a pretty nice implementation from Apache: https://xmlgraphics.apache.org/batik/
You could generate svg from your data (which is pretty easy) and pass it on to batik to show in a component or you can use their bindings to Java2D to draw.
As a bonus you can use existing tools like Inkscape to edit you drawings further.
There are existing projects which use this to do simmilar things like you want: https://xmlgraphics.apache.org/batik/uses.html

Related

Convert Shape from awt to Shape in javafx

I want to display Shape on Pane in JavaFx. I am using oracle JGeometry object selected from spatial database, it has a method createShape() but it returns java.awt.Shape.
Is it possible to create JavaFx object also so easily? Maybe I am just blind but I haven't found anything and don't want to program too much stuff on top. Thank you
Java only supports a handful of shapes, so it is not very difficult to write a little converter but if all you want to do is to draw the AWT shapes on a JavaFX canvas, then maybe this library can be helpful: http://www.jfree.org/fxgraphics2d/

Graphic library for plot/drow fractal on Java

I'm looking for a graphic library that allow me to plot a pixel point in a specific color with the purpose of draw a fractal (mandelbrot set). I've read the basic math behind fractal and I understand it, the algorithm is not difficult.
But I don't know what graphic library could I use, I don't need anything sofisticated and complex, just print a pixel set with colors. What do you suggest me? Cairo? OpenGl?.
Note: I only have experience with pygtk. I was reading the Java API and found the the fillRect method and BufferedImages but it seem a little complicate.
Thanks ;)
Unless you want to compute 3D fractals (in which case a library like JOGL Java OpenGL can help), a simple java.awt.Graphics.setColor( java.awt.Color aColor) is enough.
(as show in this program).
In other word, the default awt library in Java should be up to the task: see "Graphics: setColor(Color c)".
I have implemented both mandelbrot and the flame fractal algorithm in native java (no openGL).
The most efficient way is to just store color in an int array or similar,
and then save it as an image file (png or jpg). It is much quicker than using Graphics.

How to make a customizable graph

I'm looking to use the java2d API to make a graph in which users can manipulate certain features using their mouse - such as the scale used for an axis or move around the different points plotted on the graph.
So far all I have found is the drawX methods on a Graphics2D object, however there does not seem to be an easy way to capture a user clicking on one of these and moving it so that I can redraw the graph.
Can anyone suggest the best/easiest way to implement this? Just looking for a point in the right direction.
Not reinventing the wheel is always the best way, there are plenty of excellent libraries you can use: http://www.jfree.org/jfreechart/
If you are looking to implement this yourself, you would listen to mouse events on whatever component you're actually using to display your chart (say a JPanel), and then would have to convert between screen and chart coordinates to figure out what you need to change.

Approach to create complex 3D drawings in OpenGL ES (on Android)?

I'm new to opengl-es and I wonder how people are able to draw these much detailed OpenGL ES graphics, e.g. on Android OS. It's already hard to draw a single squre, because it's composed of triangles due to the reason that OpenGL ES obviously cannot draw anything else than triangles.
I thought about this approach:
Drawing and rendering an object in Blender.
Export it somehow as array of vertices and an array of colors
Copy this array of vertices into the Java code
Run the code
Or are there approaches to solve such problems in a better way? I do not think that people just "draw" their graphics as array of vertices in the code. I'm sure they draw them anywhere else and import it into the code.
If there is such a solution with Blender, I would be pleased to know how this is solved.
Regards.
You can save your model from Blender e.g. as Wavefront OBJ file. In Blender, you can also select to triangulate the model for you, which will result in a list of just triangles, ready for drawing.
OBJ is a very simple format, it just lists in ASCII the position of each vertex and then which vertices belong to each triangle. Either convert the OBJ to a format specific to your application (e.g. binary buffer you can directly load to OpenGL) or find yourself one of the many OBJ loaders, or write your own reader.
There are a lot of other common formats available, you should take a look at them and see if there is an importer for Android available.
What I've found is that you can Load 3D models with min3D directly to your program using:
min3d
I hope this helps.

Trying to convert a 2D image into 3D objects in Java

Hey, I'm trying to take a simple image, something like a black background with colored blocks representing walls. I'm trying to figure out how to go about starting on something like this. Do I need to parse the image and look at each pixel or is there an easier way to do it?
I'm using Java3D but it doesn't seem to have any sort of built in support for that...
This might be more compex than you think.
A solution would basically include the following steps:
Edge detection using Java 2D ConvolveOp Filter
Vectorizing the edges into a 2D model.
Extrusion to 3D
Turns out what I really wanted was a height mapper. I mapped each pixel to a certain height based on its gray-scale RGB value. If I wanted color to be independent of height, I would have two images, one with the gray-scale height map and another with a colored image of what I want the, in this case, room to look like.
As for recognizing colors from an image as a specific object other than by pixel, definitely requires something more complex. A friend was suggesting something like painter's algorithm for something like that. However, at least for me, that was being the scope of my application.

Categories

Resources