| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 
 |  
import com.sun.media.jai.codec.*;
import java.awt.image.renderable.ParameterBlock;
import java.io.*;
import javax.media.jai.*;
import java.util.*;
 
public class CreateTiff {
 
/**
* Converts a image file to TIFF and adds a private IFD
* @param fileName file to be converted
* @param tiffFile TIFF file to create
*/
public void createTiffMf(File fileName, File tiffFile) {
 
String documentName="blabla";
short typeImage=1;
FileSeekableStream stream;
RenderedOp img;
TIFFEncodeParam encodeParam = new TIFFEncodeParam();
TIFFEncodeParam tmpEncodeParam = new TIFFEncodeParam();
ParameterBlock pb = new ParameterBlock();
Vector<TIFFField> tagsPriv = new Vector<TIFFField>();
Vector extraImgList = new Vector();
 
try {
 
// PUBLIC IFD
// loads image to convert to TIFF
stream = new FileSeekableStream(fileName);
img = JAI.create("stream", stream);
// adds a tag
TIFFField aTiffField = new TIFFField(269,2,1,(Object) new String[] {documentName});
TIFFField offsetOfPrivateIfd = new TIFFField(35000,4,1,(Object) (Object) new long[] {(long)????????????}); // WHAT HERE ?
TIFFField[] arrayTF = {aTiffField};
tmpEncodeParam.setExtraFields(arrayTF);
 
// BELOW IS WHAT I WOULD LIKE TO HAVE IN A PRIVATE IFD
// defines a tag in the private IFD
tagsPriv.add(new TIFFField(0xC352,TIFFField.TIFF_SHORT,1,(Object) new char[] {(char)typeImage}));
TIFFField[] tabTagsPriv = new TIFFField[tagsPriv.size()];
tagsPriv.copyInto(tabTagsPriv);
TIFFEncodeParam privateEncodeParam=new TIFFEncodeParam();
privateEncodeParam.setExtraFields(tabTagsPriv);
Object[] montab = new Object[2];
montab[0] = ?????; // WHAT TO PUT HERE AS AN IMAGE ?
montab[1] = privateEncodeParam;
extraImgList.add(montab);
// adds an IFD
encodeParam.setExtraImages(extraImgList.iterator());
 
// CREATION OF TIFF
pb.addSource(img);
pb.add(tiffFile.getAbsolutePath());
pb.add("TIFF");
pb.add(encodeParam);
JAI.create("filestore",pb);
 
stream.close();
System.gc();
 
} catch(Exception e){
System.out.println(e);
}
}
} | 
Partager