This question already has answers here:
Can't read and write a TIFF image file using Java ImageIO standard library
(5 answers)
Closed 4 years ago.
Now I have to do some processing(such as read/save) with some .tif images, but it seems like I can not read or write the images by java. Is there any library can help me for that? And How to used it to read or save the images? Thanks for your answer.
I guess you will need to use the JAI (Java advances imaging package), take a look at this, and see this example
Java Advanced Imaging provides support for TIFF out of the box. Alternately add a Service Provider Interface Jar for TIFF on the run-time class-path of the app. and ImageIO will be able to deal with them (load them at least, it probably won't provide support for 'multi-page' TIFF writing).
Java supports reading and writing jpeg, gif and png by default, using ImageIO. In order to read tiff images, you must use a JAI plugin called jai_imageio.jar. You just put this jar in the classpath and you will be able to read tiff images.
used jai not working now, can't get "com.sun.image".
But found another package that works - jdeli. It has a class TiffDecoder, which can be used to decode(read) tiff images with alpha channel to a Buffered image. Then you can write that image using ImageIO.write
Related
I have TIFF files that contain a single image.
I need to be able to convert them to PNG inside our Java app.
Almost every search says to use JAI - which doesn't seem to exist anymore.
We currently have the itextpdf library in our system, and it looks like it can read a TIFF and write a PNG.
Anyone know how? Or can point me to the correct section of documentation?
I see that there is a TIFFImage class that looks like it can read a TIFF, and a PNGWriter that can write a PNG - but I haven't been able to figure out how to take the result of the TIFFImage (an Image object) and pass that data to the PNGWriter.
You can use standard ImageIO and my TwelveMonkeys ImageIO TIFF plugin to read the TIFF and write it back as PNG. The plugin can in most cases be used as a direct replacement for the JAI ImageIO TIFF plugin.
When the plugin is installed, your TIFF is single page, and all you care about is the pixel data, the code could simply be:
BufferedImage image = ImageIO.read(tiffFile);
if (!ImageIO.write(image, "PNG", pngFile)) {
// Handle file not written
}
I would not recommend using iText for this (and neither would Bruno Lowagie, it seems). :-)
This question already has answers here:
What's a good compression library for Java?
(3 answers)
Closed 9 years ago.
I have a problem. Currently I'm developing video game in java language. At this moment data files take about 100MB space even though game world is not big. I want to zip those text files ant protect them with password or some kind of encryption, but I can't find any good and free library for that.
Or maybe it's possible to pack data into some kind of archive without external libraries?
Update
I tried to download Zip4j, but it shows that I need source attachments and I can't find in library's site.
You can compress yor game data with the facilities provided by the JDK:
java.util.ZipFile and related classes to handle normal zip files
java.util.GZIPInput/OutputStream to compress data directly (no "files catalog" concept, just a blob).
java.util.DeflaterInput/OutputStream (like GZIP)
There exists a multitude of 3rd-Party compression classes. I personally like XZ for Java, because it provides excellent compression ratios and is easy to use through the standard stream interface (http://tukaani.org/xz/java.html).
For encryption, there are encrypting streams that are used just like the compression streams. Beware that anybody will be able to extract the "key" from your game files with a little knowledge and patience if they really want to.
You can use apache Compress Library for compressing file.
http://commons.apache.org/proper/commons-compress/
you can also compress using zip libraries at java.util.zip
Java provides several features that compress the data such as:
GZIPInputStream and GZIPOutputStream
you can also use zip with ZipFile (java.util.zip)
For encryption you could write your own FilterOutputStream and FilterInputStream where you use a Cipher to encrypt it.
Those features are working all without external libraries.
You know, png file for iphone can't display using image reader on windows.
How can convert png file for iphone to standard png file using java?
Is there any open-source library to do this?
Any response will be much appreciated.
Can Java read the 'png file for iphone'? If so, it would be trivial to write it back out1 to a PNG in a form that Windows can read.
If not you need to look into either JAI or an SPI that supports that flavor of PNG.
See ImageIO.write(RenderedImage,String,File) for details.
As leonbloy said, iOS-optimized PNGs are actually not PNGs at all, they are considered to be "CgBI" format:
http://iphonedevwiki.net/index.php/CgBI_file_format
I know this wasn't around when the question was first asked, but here's a Java converter implementation:
https://github.com/viphe/ipng-converter
yes you can convert iPhone PNG file to standard file using Java. Please go thought below link for script.
https://github.com/CuelogicTech/Convert-iOS-Application-PNG-images
I'm trying to render a pdf (with pdf-renderer or jpedal), and it can't handle an image encoded using JPX. Is there any open-source java library that can decode JPX?
JPX needs JPEG2000 which needs the JAI and imageIO libraries. JPedal has support for JPX - you just need to enable it which explained on the support section.
There is a patched version of the imageio to fix the memory bug on our site at http://www.jpedal.org/PDFblog/2011/03/java-jai-image-io-jpeg2000-memory-leak-fix/
I'm brand new to Java Advanced Imaging, and the first stumbling block I've reached is the ability to read in a 12 bit, single band, greyscale JPEG file. I've seen references to it being possible with JAI, but no code or even suggestions about how it should be done. Could someone please help me out with either a helpful link or a short code snippet?
I've been using this tutorial so far, but it hasn't helped me on this issue.
Thanks.
JAI-ImageIO will register itself into Java's ImageIO api, so you should be able to use it just by having the jai-imageio jars in your classpath an calling the normal ImageIO methods, such as ImageIO.read(file).
The problem with jpeg might be that Java has a default jpeg reader in the IIORegistry, and you may have to select the right one manually using something like ImageIO.getImageReadersForFormatName().
Another thing with the more esoteric formats is that JAI ImageIO usually has two implementations - one pure Java and the other using native binary libraries, so make sure that you include the *lib-wrapper.dll (or whatever suits your particular OS) in the LD_LiBRARY_PATH or have the in the working directory of your program. The native implementation usually supports mode format variants than the pure-java one.
we usually read JPEG 12bit grayscale images using JAI + JAI Image I/O.
Additionally to previous answers, you need the native binary libraries to read JPEG 12bit, so mediaLib library is required.
You only need the "ImageRead" operation from Image I/O:
byte[] imageBytes = ...
RenderedOp readImage = JAI.create("ImageRead", new MemoryImageInputStream(imageBytes));
Whe usually read the image files from FTP, so get the byte[] and need the custom MemoryImageInputStream that wraps a byte[] into a ImageInputStream by subclassing ImageInputStreamImpl.