Customized rendering of SVGs in java - java

I am working on a java swing application that requires rendering images in specific locations on a JPanel. Currently, I am using PNG images with the Graphics.drawImage method. The application also requires the ability to freely move and zoom the "camera", which I am accomplishing with the Graphics2D.scale and Graphics2D.translate methods.
However, a significant issue with this approach is that the images do not scale well when the application is zoomed in. I was hoping that I could get around this by using SVGs, so I downloaded the Batik library. I have been able to display an SVG using Batik's SVGCanvas, but this doesn't really solve my problem because I am unable to freely place the SVGs in the JPanel and use the SVGs alongside the java Graphics methods.
Does Batik even apply to my use case? If not, is there some other way I can freely scale and render SVGs in a JPanel just like I would with a BufferedImage? Another option would be to just use the Graphics2D methods to try to replicate the icons I want to use, but that seems unnecessarily complicated.

Related

Does HTMLUnit include a functional [HTML5] canvas 2D implementation able to render image data back to Java Code?

Basically, I'd like to be able to retrieve the HTMl[5] canvas image data created from, normal, JavaScript-based in-browser scripting. I'd like to do this in the context of a screen-scraping-type environment, from within [pure] Java code. HTMLUnit appears to fit some of the requirements.
How would I go about retrieving the canvas-rendered image data, and how complete, or not, might HTMLUnit's canvas implementation currently be (version 2.13 at time of writing)?
Two (2) HTMlUnit classes of note, might be:
com.gargoylesoftware.htmlunit.html.HtmlCanvas
com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasRenderingContext2D
Well [answering my own question], as far as can see, no, there is not a functioning HTML Canvas implementation, as of HTMLUnit version 2.13 (November 2013).
Interestingly, it might be useful to integrate the following HTML Canvas (2D) open-source solution into HTMLUnit, in order to render canvas-based graphics:
https://github.com/w3canvas/javacanvas
It should also be possible to create a WebGL canvas context by appropriating the WebGL interface/class code from something like the gwtGL project, and implementing a 3D layer atop of an existing OpenGL 2.0 Java library.
Can I haz some points now?

Adding Text to Screen with OpenGL

Currently, I am working on a OpenGL project and here is the screenshoot what I did
The question is, I want to add texts(degrees) to compass and want to do that with pure OpenGl methods. I found TextRenderer class however, couldn't manage to download it and use it. How to use TextRenderer class in my Java project? If there is any other way of adding text besides TextRenderer, would love to hear it.
My second and most important question is about merging swing/awt methods with OpenGL and using multiple objects. I wrote the program with only using one GL2 object and worked perfectly, is it sensible to use multiple openGL objects on the same frame? Furthermore, using swing methods and openGL methods together is a good idea?
I want to add texts(degrees) to compass and want to do that with pure OpenGl methods.
Unless you can live with not very pleasantly looking center stroke fonts, you have no choice but to use help from some other library or API.
Theoretically OpenGL can collaborate with OpenVG, but so far overall support for OpenVG is very poor, and OpenGL interoperability even worse. But say you had a proper working OpenVG – OpenGL interoperability working, then OpenVG was the way to go.
Practically you have to something different. A very fruitful approach is to use a font renderer library (like FreeType) together with some layout engine (like Pango) to produce an outline stroke list of the text to be rendered, which in turn can be either rendered directly using some extension by NVidia (http://www.opengl.org/registry/specs/NV/path_rendering.txt available only on the most recent NVidia GPUs) or manually tesselated into triangles, either on the CPU or by a combination of GPU Geometry and Tesselation Shaders. A huge drawback of drawing glyphs as tesselated filled outlines with OpenGL primitives is, that they will look very dirty (due to aliasing) if the used framebuffer doesn't have a multisample format (full screen antialiasing)
The next best thing is rendering the text to an image and copying that to the GPU and overlay that over the scene by rendering a textured quad. You should apply all text transformations already when rendering the quad, so that the font hinting system can make the proper adjustments on the transformed glyphs before rasterizing them.
Another approach is using texture mapped fonts. I implemented two TMF engines myself so far, but personally I advise against using this approach these days, as TMFs are resource hogs. A 200kiB TTF font can blow up to several megabytes of texture data. Maybe one day I or somebody else implements a TrueType or OpenType rendering engine with OpenCL, CUDA or Compute Shader, but until then rendering text with OpenGL is dirty business.
It boils down to
Crisp Look
Memory Efficient
Computationally Efficient
→ choose 2
After doing little research, I ve figured out how to install it and use it correctly.
Firstly, go to that web site and download suitable version of jogl for your os in case you dont have any library:
http://jogamp.org/deployment/autobuilds/master/jogl-b1011-2013-06-19_05-41-38/
Then, download that jar file and add it to your user library.
http://www.java2s.com/Code/Jar/j/Downloadjogl20jar.htm
That file contains the TextRenderer class.
If you dont know how to make one, use that link:
http://riccardotramma.com/2011/04/setup-eclipse-to-develop-opengl-glut-apps-in-java-cc-on-windows-mac/
Then, follow the instructions: http://download.java.net/media/jogl/jogl-2.x-docs/com/sun/opengl/util/awt/TextRenderer.html
It's very easy to use, I perfectly added numbers to my compass. However, not efficient as far as I can tell.

Using Swing GUI for NetBeans to Set Background of a JFrame from a Resource

My friend and I are working together to write a Java program, and I am taking on the task of designing the GUI. Our GUI requires a background image for the JFrame, and the image needs to be able to change based on the user's actions. I have placed the images that I want to use as the background in the project as a resource, and I would like to ask for help finding the resource path, and setting the resource path as the background image in the JFrame.
I am using the Swing GUI Builder for NetBeans to design the GUI. Can someone please offer me some help? I have no experience with GUIs, and my friend has little experience with basic Java coding, so we are assigning parts based on our knowledge.
If you don't want to resize the images (as the frame changes), you could simply set the frames layout to BorderLayout and use a JLabel to display the images. Otherwise you will need to construct a custom component (using something like JPanel) and render the image yourself
Looking up embedded resources is a simple process of using something like getClass().getResource(...), where the parameter is the path to the resource, where the root is the top level source folder in your project.
Take a look at...
Java: maintaining aspect ratio of JPanel background image
Performing custom painting
2D Graphics

What is a good Java lib for image transformations and backbuffer rendering without need of front buffer for server side programming?

I'm trying to find a simple library to fit my needs, but because I am really unaware of Java libs (I use to do everything from scratch in any programming language that I work with) and the exactly thing that I need is complicated for a Google search query, it would be greatly appreciated any recomendation.
What I am trying to achieve is to do some image manipulation in server side using the sumitted info from a web browser. Is not simple scale or crop, but to be able to rotate, scale and crop every single sprite and draw it in the exactly order to compose the final hight resolution image in a backbuffer then save it in bmp and make some copies in lower resolution as png.
I have no problem with the interface from client side to the server, also I have experience in game programming, so I know how to work with double buffering. What I need is a library that let me do all these images transformation and backbuffer drawing without the need of a front buffer and graphics hardware, because the output will not be the screen, and to be able to access every pixel argb from memory, able to save in various image formats and as a plus but not requiered able to render text from different font.
Thanks for any reply and any recomendations to improve my question will be apreciated too (I am new around here).
A couple of libraries you may find helpful for server side image processing in Java:
JH Labs image filters : http://www.jhlabs.com/ip/filters/index.html
imgscalr image scaling library: https://github.com/thebuzzmedia/imgscalr
Also don't forget the good old BufferedImage API that is already in Java: it has quick a decent range of functionality for basic image manipulation (cropping etc.)
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html

drawing framework in java

I'm looking for a java 2d drawing framework. I'm building an application in which you load an image, and you should be able to draw on top of the image. But everything which is drawn should be selectable, modifiable, have properties etc. Actually Eclipse GEF (or Graphiti) looked really good, but that seems to be focused on drawing diagrams only. I would also need support for freehand drawing, bezier curves, lines etc.
Anybody know something like Eclipse GEF but which also supports freehand drawing and bezier curves? Or maybe it does and I didn't look quite good enough?
You can quickly write a simple editors yourself using JPanel and a custom paintComponent() method. But creating a useful editor with undo, etc. is a lot of work.
Try jfig which is shareware (free for 30 days, then $30). It has a framework with editor components plus a default editor which you can tweak.

Categories

Resources