1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.examples;
18
19 import java.awt.image.BufferedImage;
20 import java.io.ByteArrayOutputStream;
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.commons.imaging.Imaging;
25 import org.apache.commons.imaging.ImagingException;
26 import org.apache.commons.imaging.formats.tiff.TiffImageParser;
27 import org.apache.commons.imaging.formats.tiff.TiffImagingParameters;
28 import org.apache.commons.imaging.formats.tiff.constants.TiffConstants;
29
30 public class ImageWriteExample {
31 public static byte[] imageWriteExample(final File file) throws ImagingException, ImagingException, IOException {
32
33 final BufferedImage image = Imaging.getBufferedImage(file);
34
35
36 final TiffImagingParameters params = new TiffImagingParameters();
37 params.setCompression(TiffConstants.COMPRESSION_UNCOMPRESSED);
38
39 try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
40 new TiffImageParser().writeImage(image, baos, params);
41 return baos.toByteArray();
42 }
43 }
44
45 }