java - How do I convert multiple png images to a single tiff file -
is a byte array of images I have png format I need to convert it to a TIFF file and then associated byte array In this quarrel file will contain many images.
I have searched a lot, but I have not succeeded. Grab I have to do this only in Java !! :) Can someone provide some insight regarding my problem?
I do not benefit from Imejmejik so, because I have a server component that manages the conversion, and then delivers it to the backend as the flock. The client creates a byte array that translates into a PGG image.
The solution is below.
import javax.imageio.ImageIO; Import javax.imageio.ImageWriter; Import javax.imageio.IOIO image; Import javax.imageio.ImageWriteParam; Import javax.imageio.stream.ImageOutputStream; Import java.awt.image.BufferedImage; Import java.io * *; Import java.util.Iterator; / ** * * * This class is used to convert multiple pictures into single multi-page TIFF image file. * * / Public class multi-generating generator {Private Static String Compression Type = "JPEG"; Public static boolean generates multiplexif (string denname, string outputfilename) throws an exception {Boolean origin = false; ImageOutputStream Ios = null; Author Author = Faucet on Image; Try {// File directory confirmation file for file dir = new file (dirName); If (null! = DIR and amp !! Diaeresis directory ()) {new Failnotfound Exception ( "there is no directory with the name" + Dinnam); } // Verify that the images are present in the file [] files = dir.listFiles (); If (null == files || files.length == 0) {new filenoutound exception ("no image files to process"); } Else {// Create Output File on Disk File File File = New File (DINN + OutputFilename + ".tif"); Ios = ImageIO.createImageOutputStream (file); // Get the appropriate Tiff Image Author Ethernet & lt; ImageWriter & gt; Authors = ImageIO.getImageWritersByFormatName ("Tiff"); If (Zero == authors ||! Writers. HasNext ()) (new exception throw ("The appropriate tiff writer was not found");} Author = ImageIO.getImageWritersByFormatName ("Tiff"). Next (); writer.setOutput (IOS ); set compression parameter // TIFF image ImageWriteParam param = writer.getDefaultWriteParam (); //param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); //param.setCompressionType(compressionType); //param.setCompressionQuality(0.9F) ; // loop through all the image files and them (the gut i = 0; i & lt; files.length; i ++) type of output TIFF image {InputStream fis = null; Int dotIndex = files [i] .getName (). LastIndexOf ('.'); DotIndex = DotIndex> gt; dotIndex: files [i] .getName () length (); string filename = files [i] .getName (). Substrings (0, dot index); if (! FileName.equalsIgnoreCase (outputFileName) ) {try {fis = new BufferedInputStream (new file InputStream (files [i])); Bfede image = Imejiyo. Reed (FIs); IIOIge img = new IIOImage (image, blank, blank); if (i == 0) {Author; written (zero, img, ultimate); } Other {authors.writeinset (-1, IMG, the ultimate); } Image.flush (); } Finally {if (null! = Fis) {fis.close (); }}}} Ios.flush (); Generated = true; }} Hold (FileNotFoundException pre) {generated = false; } Hold (IOException pre) {generated = false; } Hold (exception before) {generated = false; } Finally {if (null! = Ios) ios.close (); If the author (empty! = Author) Diesz (); } Return yield; }}
Comments
Post a Comment