I have Java Swing application with maximized bounds for JFrame. The application is distributed as jar file up to now.
Initially for background image I have used some large arbitrary image file of png-format. And I do have a code which can load and set image as background for JFrame.
Now, I got a new image from designer in both cdr and png format. Png image is 5 by 4 thousand pixels now.
My requirements:
to minimize image file size
to support different screen resolutions
What would be the best option to meet requirements?
Resize file to 1920x1080 and keep as png, and resize at runtime to smaller images if needed according to resolution
Keep file as cdr or some other vector format. But I am not sure Java can easily read and convert it to BufferedImage
If you have the opportunity to get the file in .svg this will fit your needs the best. You could then have a look at Apache's Batik library and its rasterizer to render the image.
What would be the best option to meet requirements?
Resize file to 1920x1080 and keep as png, and resize at runtime to smaller images ..
..or larger - time goes on, screen resolutions get bigger (& bigger)..
.. if needed according to resolution.
Yes. I think that is the best option.
Loading a library to render an SVG or EPS to BufferedImage at run-time seems like overkill for a BG image.
Deployment
The application is distributed as jar file..
Applications that use images often have a GUI. Does this app. have a GUI?
If so, it would be optimal to deploy it using Java Web Start.
The Jars for JWS can be downloaded lazily and programmatically, and are refreshed when updated, so the image should probably be in a separate Jar of its own to avoid downloading a new version every time there is a bug fix. When putting an image (or compressed media files in general - sound, video,..) use 'no compression'. Zip does nothing good for these already highly optimized, or at least very specialized, data formats.
Related
I'm currently using the gdx-freetype library to generate the BitmapFonts for my game. It's really convenient since I can use it to handle the different screen sizes on Android. The problem is that it takes a long time for a font to be made. At startup I generate some BitmapFonts in a few different sizes (from the same .ttf file), so the time spent generating fonts, adds to my loading time. This is a problem, since it can easily take 5-6 seconds to generate the fonts.
Is there anything I can do to speed up the process or should I try some alternative to gdx-freetype? Perhaps I'm approaching this problem in a wrong way?
As Tenfour04 correctly points out in the comments, the way to do this is to only generate the fonts once when the game first loads, then save them as files. Subsequent runs will simply load them from the files which will be much faster.
I've heard good things about the gdx-smart-font project which does exactly this, although I should add that I've never actually tried it myself...
This class provides several benefits:
Creating fonts for different screen sizes using Hiero or BMFont can be
troublesome, if you have 4 fonts of different sizes and are targeting
5-6 different screen sizes, you then must generate 20-24 bitmap font
pngs. By using generated fonts they can be dynamically scaled at the
time of creation based on screen size.
Generating fonts cuts down on app download size, no need to include
pngs.
Generating fonts can add significant time to app startup time. Caching
the generated fonts to file, and only regenerating when needed allows
for fast app startup most of the time.
Having an ecommerce website, We have thousands of product images. On checking pagespeed on google it shows me something like this:
I was wondering, if there is any built in feature in Java or any third party library is available with which we can losslessly compress all the images that we host. Hence we can save few KBs of our customers.
On searching through internet I found few like punnypng and kraken which are paid, hence we do not have heavy image uploaded every month, subscribing to them is not worth. I would prefer any built in feature in Java or any open source third party library.
I came across JAI, but not sure about whether it addresses this problem or not. Anyone with hands-on experience with this?
P.S. We are using Java 8
Have you looked at classes in the javax.imageio package (http://docs.oracle.com/javase/7/docs/api/javax/imageio/package-summary.html) ?
You can do decoding and re-encoding of the images. The class ImageWriteParam (http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageWriteParam.html) lets you customize the compression settings.
~600 KB jpeg images are quite large for screen, though not for print. Having several images on a page would mean making more or less "thumb" views being smaller. And provide an individual product page with higher resolution, say 600 KB JPEG.
Standard ImageIO suffices for conversion, see #NicolaFerraro.
Faster page loading can be achieved on the overview page with multiple images, by storing the smaller views into one large image. PNG might then be appriopriate to prevent JPEG artifacts.
To provide a higher resolution for a print, one can use the CSS media setting.
Check thumbnailator. It is great at making smaller images from larger images.
Besides you should consider when you are going to make these smaller images. At each call, at the first call (any keeping a cache), ...
Our site have a posibility to load user pictures. User can load absolutely any file(we believe that it will a picture at the moment). On page we show a lot of pictures thus we have a huge internet traffic. we want to compress pictures on server. I have found following article about picture compressing.
How to compress jpg file?
But there are explained how to compress concrete format. Is there universal way for compressing any picture?
A picture is a very broad term that could also include vector graphics, pictures that are in a format that browsers usually can't display (like psd files).
I would recommend to use the gd lib or imagemagick on the server side to convert them all (or at least these that are supported by your choice) to a standarized format (like jpg) that can be displayed in a webbrowser and get compressed (maybe also resized).
100% of possible image files a user could upload can't be converted afaik.
I'm having difficulty locating a Java 2D based library for developing a paint program.
All the libraries I find seem to be for:
animation
graphing
games
None of which are useful to me for a paint program. (This particular project is primarily for webcomics and print comic books.)
I'm mostly interested in something that abstracts file IO for images that are practically too large to load into a BufferedImage object.
Adobe's tools for example are probably not loading whole 10MB (compressed) image files into memory -- once decompressed, that's just too much physical memory to devote to caching the image (especially if you open a dozen of them at once), so there must be a framework in those applications for managing the files on disk and buffering just the currently relevant areas in memory.
I imagine it would at least have an Image subclass that works the
same way as BufferedImage while abstracting away the fact that the
image is coming and going from the file instead of memory.
An additional wrapper that allows me to zoom in on a rectangular
area or zoom out and buffer up the scaled, visible portion (for
display) would be extra nice.
A layering system with blending modes would be super-sweet, although
I expect I'll have to build that myself.
Have you tried looking at StdDraw? It's got some basic drawing in it. StdDraw can be downloaded here
What could be the efficient way to generate fixed size thumbnails for large size images in Java?
I have a multiple directories/sub-directories to scan for image files and generate thumbnails for each image. Can I browse multiple directories at same time and generate thumbnail simultaneously? I'm thinking of having two types of processes:
To scan directories. (Multiple but limited thread count).
To generate thumbnail. (Single thread as image IO could eat too much memory) .
Any suggestions?
Search on Image Magick. It's a great library for programmatic image manipulation.
I had a website where I simply called the command-line tools (command was "convert"), and passed the desired pixel width x height parameter to generate thumbnails for a directory of images. This is essentially what I did on the backend: http://www.ibm.com/developerworks/linux/library/l-graf/
If you need to do this dynamically, at run time, take a look at http://www.imagemagick.org/script/index.php Looks like they have a package for Java that hooks into the very rich Image Magick API, called JMagick.