Java Drawing shapes to file of 2D object - java

I have a play framework application which I want to be able to produce a product label from. I have the label design in illustrator. It consists of a black circle, white writing with a QR code in the middle, also has curved text.
I want to create a high resolution PDF and/or image file of this design on the fly. All most all of the drawing stuff I find for java relates to swing.
Anyone done this?

The basic class which allows creating an image programatically is BufferedImage and the corresponding Graphics2D class. You are not forced to use it with Swing. You can easily convert it to common graphic formats like PNG. Then you can save it as an image file or place it in a generated(e.g. with iText) PDF.
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html
In other words - yes, it can be done.
But if I ware you I would consider exporting the design from Illustrator to a file and use it as a resource in your application. But if you need to scale it programatically you ought to consider using SVG format to avoid loosing quality. Java does not have build-in support for vector images so you should look at
Apache Batik

Related

Embed Graphics2D into itext without absolute positioning

I'm creating PDFs with iText (LGPL) which include some Text and self-drawn (Graphics2D) images.
My current solution is to draw the images on a BufferedImage and then include it in the PDF, which has several drawbacks:
If printed, the images just look ugly, a way to circumvent this is to use larger images, and with 3000*3000 it looks ok. But this leads to the next problem: time. It takes several seconds to compress one image (I haven’t found a way to disable it, and files would be huge without compression).
PdfGraphics2d from iText looks good, but has one major drawback: it’s only able to draw to the background of the PDF, and there seems to be no way to wrap it in some kind of element.
Is there a way to draw on a PDF without having to use absolute positions? I’m using Graphics2d because it’s used also to provide a preview in the UI.
You can wrap a PdfTemplate inside an Image object without losing any of the vector image's quality. In most cases, you'll use the Image object to add raster images to a PDF document as an Image XObject. However, in this case, the PdfTemplate will be added as a Form XObject using its original vector data. Another situation when this happens, is when you add a WMF file; such as file is converted into PDF syntax automatically.

How to make a SVG map in android? (and place markers on the map)

I'm making an app for a real life game. The app needs to use a custom map that uses scalar vector graphics (SVG). The map I'm using provides very accurate detail, such as door locations inside a building; This is why i'm using SVG instead of the maps api.
Now I know there is an api for svg (http://code.google.com/p/svg-android/), so here is what I need help with:
1) The image must be zoomable. The only reason for using the SVG graphics is for clean zooming.
2) I need to place dynamic markers (images, or buttons w/ numbers) on the SVG image. An SQL table has an image, and a location. The table will be updated, added to, and removed from. I need to place said images on top of the SVG image, and possibly each other. Coordinates and math aside, how do I place the images on top of each other (can't use XML since they aren't static).
I need to use Android 2.2
The default browser in 2.2 doesn't support SVG. You can target Opera Mobile, which supports SVG and other new technology much better, but it won't be a native app.
The first step I'd try would be designing the interface in Inkscape, then you can reference the .svg file from HTML and move elements with javascript.
flying-pigs,
If i understand your question, you want to display a SVG like that on your phone ? So you can display user location on that map.
I describe a working solution here : Add SVG Tile Provider
Let me know if you have other questions about GG Map

Optimizing jar file size (images) when developing java client supporting multiple languages

I am developing the Java client which should support several languages. For translation of the text I use Java ResourceBoundle and it works okay.
Now the problem is with images. The client should load around 50 images which are specific cards for a board game. Each image has a title. So if I have N languages I should prepare 50*N images and put then into the jar file.
Each language support would add around 1 Mb to the size of jar file.
Do you think I should
Generate jar which support all the languages?
Generate many jars which would support English and a local language?
Have one set of image without titles and attach title to the image using Java JLabel?
I advise another option altogether.
Have a set of images without text, and use AWT's Graphics2D to add the text in the necessary language (as opposed to doing so with a JLabel).
Graphics2D g = imageBase.createGraphics();
// color, font, etc settings
g.drawString("title", 0, 0);
g.dispose();
You can modify the parameters of g.drawString as necessary to draw the correct title at the correct coordinates. If you wish to center the title, you can find a nice tutorial here.

SVG constructive area geometry?

Are there SVG functions that perform CAG operations similar to those that Area provides in Java (http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Area.html)?
I would like to perform those operations directly using an SVG library (e.g. Batik), not through the Batik Graphics2D class that does SVG export (since I would rather use the SVG API than Java2D).
Cheers
SVG doesn't have any functions built into them, its mearly a graphics drawing spec..(with the exception of some animation functionality)
I would preprocess the vector values your app is using and then apply them to the rendering of the SVG.
Without knowing your platform, or your application of the SVG...its hard to help any further. SVG can be used in a lot of ways and places! :)
The references to Java allow me to assume that your using it as your interface engine? but thats about it..if you want to know the area of the circle, you would have to find the circle in the DOM tree, extrude the attributes from the the node, and just push them into a standard CAG class to do the math for you.

Tiles for tiff images in java ? or java wrapper for libTiff?

I am converting pdf to tiff images for one of my project.
Than I using iipserver to generate tiles for the tiff images on fly. But this process is killing my CPU.
so I thinking of generating tile in advance and showing them directly instead of using iipserver. I researched into iipserver and got this libTiff c++ utility which is doing tiling work for the same server.
So I wanted to know is there any java wrapper for this libTiff or are there any other method from which i could generate tiles directly from tiff image or directly from pdf pages to tiles?
ImageJ can handle Tiled Pyramidal TIFF. JAI can handle MipMaps generated from TIFF files as well.
And if you're looking for a ready-made solution, take a look at djatoka.
In the end , I got the solution. There are few points that I want to explain
1) Tiles parameter in any tiff image is just a metadata value, so
there is nothing physically marking of tiles in an image
That best way I found to generate tiles out of image is BufferedImage class method:
bufferedImage.getSubimage(x, y, w, h)
Now play with this method in a loop for image matrix as per your needs.
It worked 200% perfect for me.. cheers to all :)

Categories

Resources