K
Kenneth
We have workflow process that was written in power builder that we are
converting piece by piece to java. The function I am working on takes a
inbound fax and separtes the pages for submission into the workflow
process. I'm having a problem with the format of the resulting tiff
images. We have a custom vendor supplied DLL that burns in the
annotations that was written a vendor that is no longer available. The
DLL is part of the workflow process so rewiting it would require us to
rewrite the workflow app and we are not ready for that. My problem is
that after I split the fax into the pages I want the images are
viewable from any viewer. However a call to the afore metioned DLLl
returns a error 131081. I don't know what the error code means just
that a 0 means everythings ok. I have looked at the properties of the
images from the old process and my java program. The only difference in
in the Strips i.e RowsPerStrip, StripOffesets and StripByteCount. Can
anyone tell what I'm doingwrong? I have modified the orignal code to
write the images to a file verses the ByteArray I use normally.
Code Fragment::
Vector<PlanarImage> images = new Vector<PlanarImage>();
FileSeekableStream faxStream = new FileSeekableStream(_faxImage);
try {
ParameterBlock pb = new ParameterBlock();
pb.add(faxStream);
TIFFDecodeParam param = new TIFFDecodeParam();
pb.add(param);
ArrayList<PlanarImage> faxPages = new ArrayList<PlanarImage>();
long nextOffset = 0;
do {
RenderedOp op = JAI.create("TIFF", pb);
faxPages.add(op);
TIFFDirectory dir = (TIFFDirectory)op.getProperty("tiff_directory");
nextOffset = dir.getNextIFDOffset();
if(nextOffset != 0) {
param.setIFDOffset(nextOffset);
}
} while(nextOffset != 0);
if(faxPages.size()<2){
faxStream.close();
throw new Exception("****Error**** Invalid fax received "+
_faxImage.getName()+ ". Number of pages = " +
String.valueOf(faxPages.size()));
}
TIFFEncodeParam encodeParam = new TIFFEncodeParam();
TIFFField[] extras = new TIFFField[6];
extras[0] = new TIFFField(282,TIFFField.TIFF_RATIONAL, 1,
(Object)new long[][] {{(long)200,
(long)1},{(long)0 ,(long)0}});
extras[1] = new TIFFField(283, TIFFField.TIFF_RATIONAL, 1,
(Object)new long[][] {{(long)200,
(long)1},{(long)0 ,(long)0}});
extras[2] = new TIFFField(296,TIFFField.TIFF_SHORT, 1,(Object)new
char[]{2});
extras[3] = new TIFFField(274,TIFFField.TIFF_SHORT, 1,(Object)new
char[]{1});
extras[4] = new TIFFField(254,TIFFField.TIFF_LONG, 1,(Object)new
long[]{0});
extras[5] = new TIFFField(305,TIFFField.TIFF_ASCII, 1,(Object)new
String[]{"FaxFileImport"});
encodeParam.setExtraFields(extras);
encodeParam.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
FileOutputStream out1 = new FileOutputStream("c:\\page1.tif");
FileOutputStream out2 = new FileOutputStream("c:\\page2.tif");
ByteArrayOutputStream bStream1 = new ByteArrayOutputStream();
ImageEncoder encoder1 = ImageCodec.createImageEncoder("TIFF", out1,
encodeParam);
encoder1.encode(faxPages.get(0));
int nPages = faxPages.size();
for(int i=2;i<nPages;i++){
PlanarImage extraPage = faxPages.get(i);
images.add(extraPage);
}
encodeParam.setExtraImages(images.iterator());
ByteArrayOutputStream bStream2 = new ByteArrayOutputStream();
ImageEncoder encoder2 = ImageCodec.createImageEncoder("tiff", out2,
encodeParam);
encoder2.encode(faxPages.get(1));
faxStream.close();
converting piece by piece to java. The function I am working on takes a
inbound fax and separtes the pages for submission into the workflow
process. I'm having a problem with the format of the resulting tiff
images. We have a custom vendor supplied DLL that burns in the
annotations that was written a vendor that is no longer available. The
DLL is part of the workflow process so rewiting it would require us to
rewrite the workflow app and we are not ready for that. My problem is
that after I split the fax into the pages I want the images are
viewable from any viewer. However a call to the afore metioned DLLl
returns a error 131081. I don't know what the error code means just
that a 0 means everythings ok. I have looked at the properties of the
images from the old process and my java program. The only difference in
in the Strips i.e RowsPerStrip, StripOffesets and StripByteCount. Can
anyone tell what I'm doingwrong? I have modified the orignal code to
write the images to a file verses the ByteArray I use normally.
Code Fragment::
Vector<PlanarImage> images = new Vector<PlanarImage>();
FileSeekableStream faxStream = new FileSeekableStream(_faxImage);
try {
ParameterBlock pb = new ParameterBlock();
pb.add(faxStream);
TIFFDecodeParam param = new TIFFDecodeParam();
pb.add(param);
ArrayList<PlanarImage> faxPages = new ArrayList<PlanarImage>();
long nextOffset = 0;
do {
RenderedOp op = JAI.create("TIFF", pb);
faxPages.add(op);
TIFFDirectory dir = (TIFFDirectory)op.getProperty("tiff_directory");
nextOffset = dir.getNextIFDOffset();
if(nextOffset != 0) {
param.setIFDOffset(nextOffset);
}
} while(nextOffset != 0);
if(faxPages.size()<2){
faxStream.close();
throw new Exception("****Error**** Invalid fax received "+
_faxImage.getName()+ ". Number of pages = " +
String.valueOf(faxPages.size()));
}
TIFFEncodeParam encodeParam = new TIFFEncodeParam();
TIFFField[] extras = new TIFFField[6];
extras[0] = new TIFFField(282,TIFFField.TIFF_RATIONAL, 1,
(Object)new long[][] {{(long)200,
(long)1},{(long)0 ,(long)0}});
extras[1] = new TIFFField(283, TIFFField.TIFF_RATIONAL, 1,
(Object)new long[][] {{(long)200,
(long)1},{(long)0 ,(long)0}});
extras[2] = new TIFFField(296,TIFFField.TIFF_SHORT, 1,(Object)new
char[]{2});
extras[3] = new TIFFField(274,TIFFField.TIFF_SHORT, 1,(Object)new
char[]{1});
extras[4] = new TIFFField(254,TIFFField.TIFF_LONG, 1,(Object)new
long[]{0});
extras[5] = new TIFFField(305,TIFFField.TIFF_ASCII, 1,(Object)new
String[]{"FaxFileImport"});
encodeParam.setExtraFields(extras);
encodeParam.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
FileOutputStream out1 = new FileOutputStream("c:\\page1.tif");
FileOutputStream out2 = new FileOutputStream("c:\\page2.tif");
ByteArrayOutputStream bStream1 = new ByteArrayOutputStream();
ImageEncoder encoder1 = ImageCodec.createImageEncoder("TIFF", out1,
encodeParam);
encoder1.encode(faxPages.get(0));
int nPages = faxPages.size();
for(int i=2;i<nPages;i++){
PlanarImage extraPage = faxPages.get(i);
images.add(extraPage);
}
encodeParam.setExtraImages(images.iterator());
ByteArrayOutputStream bStream2 = new ByteArrayOutputStream();
ImageEncoder encoder2 = ImageCodec.createImageEncoder("tiff", out2,
encodeParam);
encoder2.encode(faxPages.get(1));
faxStream.close();