D
David McDivitt
I am writing an app to harvest faxes from a fax server and load into a
database. Several things may be in the same fax, so different pages may be
used for different things. Users will work all the pages individually,
associating them with whatever. My initial plan was to save the original
TIFF file as however many JPEG files, one for each page.
Documentation on the JPEGEncodeParam class says to use the JPEG classes
directly if more control is needed. It also says a single-band color
defaults to grayscale. I need black and white.
To save space I may just save the TIFF file as it is in the database and
pull out images, converting to JPEG, as needed. That would require another
table and degrade performance since images would not already be converted.
If anyone knows how to save JPEGs as black and white please advise. Thanks
public static void main(String [] args) throws Exception {
JPEGEncodeParam param = new JPEGEncodeParam();
param.setQuality(0.25f);
SeekableStream s = new FileSeekableStream(new
File("C:/tiff/0862904.TIF"));
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, null);
int pageCount = dec.getNumPages();
if (pageCount > 9) pageCount = 9;
for (int page=0;page<pageCount;page++) {
RenderedImage image = dec.decodeAsRenderedImage(page);
FileOutputStream stream = new
FileOutputStream("C:/jpg/"+page+".jpg");
ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG",
stream, param);
encoder.encode(image);
stream.close();
}
}
database. Several things may be in the same fax, so different pages may be
used for different things. Users will work all the pages individually,
associating them with whatever. My initial plan was to save the original
TIFF file as however many JPEG files, one for each page.
Documentation on the JPEGEncodeParam class says to use the JPEG classes
directly if more control is needed. It also says a single-band color
defaults to grayscale. I need black and white.
To save space I may just save the TIFF file as it is in the database and
pull out images, converting to JPEG, as needed. That would require another
table and degrade performance since images would not already be converted.
If anyone knows how to save JPEGs as black and white please advise. Thanks
public static void main(String [] args) throws Exception {
JPEGEncodeParam param = new JPEGEncodeParam();
param.setQuality(0.25f);
SeekableStream s = new FileSeekableStream(new
File("C:/tiff/0862904.TIF"));
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, null);
int pageCount = dec.getNumPages();
if (pageCount > 9) pageCount = 9;
for (int page=0;page<pageCount;page++) {
RenderedImage image = dec.decodeAsRenderedImage(page);
FileOutputStream stream = new
FileOutputStream("C:/jpg/"+page+".jpg");
ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG",
stream, param);
encoder.encode(image);
stream.close();
}
}