How to save an edited TIFF?

C

carl.manaster

I'm new to Java and exploring JAI. I'm opening grayscale TIF images
with

RenderedImage image = JAI.create("fileload", filename);

, getting an editable raster with

WritableRaster raster = image.copyData(null);

, and changing a pixel with

raster.setSample(points.x, points.y, 0, 0);

So far, so good.

Now, how do I get my raster into an image and save that image to a new
TIF?

If I'm barking up the wrong tree altogether, of course, please let me
know.

Thanks,
--Carl
 
R

Roedy Green

I'm opening grayscale TIF images

ImageIO won't help. It handles only BMP, JPG, GIF, and PNG and it
won't write GIF.

JAI supports BMP, GIF (read only), FlashPix (read only), JPEG, PNG,
PNM, TIFF, and WBMP.


from the JAI faq.

How do I save an image as a TIFF (or: BMP, JPEG, PNG, ...)?
Use the "filestore" operator:

RenderedOp op = JAI.create("filestore", image, filename, filetype,
encodeParam);
 
C

carl.manaster

Thanks, Roedy,

That put me on track. For posterity's sake, here's my working code:

private static void writeTifFile(
WritableRaster raster,
RenderedImage image,
String filename) {
BufferedImage bi = new BufferedImage(
image.getColorModel(),
raster,
true,
null);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(bi, 0, 0, null);

TIFFEncodeParam params = new TIFFEncodeParam();
params.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
JAI.create("filestore", bi, filename, "TIFF", params);
}

Peace,
--Carl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top