I have developed a swing application that displays images, so I have a large amount of images (more than 1500), I'm asking what is the best way to add these images to the swing project, is it just inserting the images in a specific package, or is it better to add a zip file containing the images, or ...?? Thanks in advance
The "right" answer here depends on what you plan to do with the images. If you're using them as icons, you might want to externalize those into a zip file or even a directory structure you ship with the app so they can be swapped out if you ever find the need. A zip file is pretty easy to access from code, and you can even organize it like a java source / package structure and drop it on the classpath so you can load the images with getClass().getResourceAsStream("whatever"). That has the advantage of not conflating actual source code with resource files like images.
Related
As a challenge and practicality, I have a few images I want to include inside my jar for a mod I'm developing. But as is the compiled jar with the images ends up weighing over 25 MBs, which is not ideal. So my idea is to simply compress them and add that compressed package as a resource. But doing so doesn't appear to shrink the file size that much. So the two questions I want to ask (if that plan makes sense) what's the best way to compress a bunch of images and then being able to utilize them while running the game/program?
Lossy image compression is one way to reduce file size, but when dealing with images that cover the entire screen the drop in quality can easily be noticed, which is not what I want.
Another solution is to simply not have it part of the mod and instead needs to be downloaded individually and read from it. But that's a little cheap and still would have to download the same amount of MBs to get the full experience.
Note. I don't need to compress them in my program, just read from them when they are compressed.
We need to be able to load large (typically >10,000px in one dimension but potential larger) images into Java. The user will need to zoom/pan the image and then click points which the program then uses to make distance measurements.
As always I'd rather not reinvent the wheel so would like a library that will handle reading popular formats (JPG and TIF), but also take care of memory handling, tiling etc. I'm assuming proper image editing programs like GIMP and Photoshop don't read large images directly into memory but rather read subsets of the data as needed?
The solution needs to be open source as this is an academic project. It also needs to be cross-platform so native libs are out unless they are available for Windows, Linux and OSX.
I'm making two Java applications one to collect data, another to use it. The one collecting will be importing a file from the other which will include data and images and will be decrypted.
I'm unsure what filetype to use. So far all of the data is in XML and works great but I need the images and was hoping not to have to rely on giving all the images in a folder with a path reference.
Ideas?
well, I think that the best way is to create your own format (.myformat or .data). This file will be in fact a Zip file that contains your XML file and images.
There is no perfect example writen in java as far as I know. However, here are some examples :
Not in java
The best example is, as #Bolo said, the odt format. Indeed, OpenOffice writes the doc in an xml file, and the images too. All that is wrapped in an odt file.
The .exe file is an other example. The C files and the resources are put in a single file. try to open it with 7-zip, you'll see.
The Skyrim plugins are .esp file that contain the dds, the scripts, the niffs (textures)...
In java
The minecraft texture packs are a zip file that contains a .mcmeta file (the infos) and the textures (.png)
Jar files are like exe.
If both programs are in java you could also go with serialization, which is basically saving an object as a file (suffix will be .ser I think) and then being able to retrieve it. You should google it, even if it won't help right now it is quite good to know about it.
I'd suggest using JSON. Gson is a decent library.
You can embed images as byte arrays.
Save the serialized string in a file with a preferred extension, read it from the second application, de-serialize, and reconstruct images.
You can convert binary image data to text with Base64 encoding and this way you can embed your images in XML. [1]: http://en.wikipedia.org/wiki/Base64
I'm trying to create an app and have the ability to save files to /data/data/(packagename)/files or a directory similar to that. The goal would be to have a pdf or doc handler, as necessary, open the files stored on the internal storage and be viewed by the user. I have the code to get a pdf reader that is installed and display the file but I do not know how to package the files so they are installed in a directory like the one above. Also, if I am able to do this would I use getResources to access the files? How should the file structure look in eclipse to make this happen on install of the APK?
I do prefer to have the files stored internally (they are small) and not on the SD card.
I admit I am new to this and am trying to learn as I go. Thanks for the help!
As I understand your approach you only need to place your files to assets folder of your application and then just copy them to the internal storage. Read more here.
I've been talking with an artist and she is planning to send me .ai files for a project I'm working on that is using Java for its front end. Unfortunately, I'm having a lot of trouble searching for this issue because search engines are replacing .ai with "a" (even when I specifically say not to) or are searching for artificial intelligence. Obviously neither of those are what I'm looking for.
Is anyone aware of a Java library capable of rendering .ai files as static images?
.ai file are vector graphics, they shouldn't be used in production. When the final copy of your image is ready your artist should be sending you a .png / .jpg or similar end working file.
.ai stands for Adobe Illustrator and are intended for use only by Illustrator. It's like a developer creating .java files and sending them to a client, it's more likely they'd want a executable jar or a program installer.
Worst case scenario you should install CS5.5 (there's a trial version) and exporting the .ai files to a static file type yourself.