0

Input image

Output Image

I am merging a group of tiff images into one and at the same time want to resize/rescale the final tiff image in java . Is there a way to do that . Below was my logic for merging . I am successfully in merging but can't increase the height and width .

ByteArrayOutputStream baos=new ByteArrayOutputStream();
            //ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", baos, params);
            List<BufferedImage> imageList = new ArrayList<BufferedImage>();   
            for (int i = 1; i < images.size(); i++)
            {
                         imageList.add(resizedImage); 
            }
            params.setCompression(params.COMPRESSION_NONE);

            params.setExtraImages(imageList.iterator()); 
            TIFFField[] extras = new TIFFField[2];
            extras[0] = new TIFFField(282, TIFFField.TIFF_RATIONAL, 1, (Object) new long[][] { { (long) 300, (long) 1 },
                    { (long) 0, (long) 0 } });
            extras[1] = new TIFFField(283, TIFFField.TIFF_RATIONAL, 1, (Object) new long[][] { { (long) 300, (long) 1 },
                    { (long) 0, (long) 0 } });

            params.setExtraFields(extras);
            ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", baos, params);
            encoder.encode(images.get(0));

baos does holds the bytes for the final image which i am converting into a tiff

Final steps of creating a combined tiff image

FileOutputStream fos = new FileOutputStream (new File(inputDir + "\\combined.tiff")); 
baos.writeTo(fos);

But how to increase the height and width . Please make a note that i had done everything in the java code and all at the run time

user207421
  • 305,947
  • 44
  • 307
  • 483
User146378
  • 215
  • 1
  • 3
  • 11
  • what do you mean? make all those bufferedimages smaller before adding theM?? thats a silly little question - based on what you have done – gpasch Mar 24 '16 at 16:06
  • @gpasch : Multiple tiff's uploaded and I had merged them to one big tiff file . All the uploaded tiff's having Dimensions 992 X 416 and DPI was 300 .The end result which was combined tiff should have something 2550 X 3300 dimensions and that's what I am trying . I am successful in merging all the uploaded tiff's into one and also increased the DPI to 300 but stuck with the dimensions . – User146378 Mar 24 '16 at 16:36
  • 1
    Increasing the size decreases the DPI. You can't manufacture dots that aren't there, altough you can interpolate. But the true DPI can't be increased. Your question doesn't make sense. – user207421 Mar 25 '16 at 03:08
  • Seems to me what you are talking about is more like the JAI [Mosaic Descriptor](https://docs.oracle.com/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/MosaicDescriptor.html)? Or do you want a multi-page TIFF, and simply misunderstand what DPI/dimensions mean for a multi-page TIFF? In the latter case, the dimensions are not added... What you'll see in the file info, is usually just the dimensions for the first page. – Harald K Mar 29 '16 at 08:58

1 Answers1

0

I'll give it a try since I don't understand what you are doing with the tiffs:

      List<BufferedImage> imageList = new ArrayList<BufferedImage>();   
        for (int i = 0; i < images.size(); i++)
        {
           BufferedImage b=new BufferedImage(1500, 1500, BufferedImage.TYPE_INT_RGB);       
           Graphics g=b.getGraphics();
           g.drawImage(images.get(i), 0, 0, b.getWidth(), b.getHeight(), null);
           imageList.add(b); 
        }

This will convert the images from the list images to size 1500, 1500 and store them in the list imageList, which will then use to create the tiffs.

gpasch
  • 2,672
  • 3
  • 10
  • 12