Home > Default > Saving a tiff image N preserviing its resolution

Saving a tiff image N preserviing its resolution

November 30Hits:0
hi guys ,
I am facing a problem saving an existing tiff file to a tiff format.
My original image is of 600 dpi both horizontal and vertical resolution.
When i save using my patch of code the resulting image is 96dpi in resolution.
I need to make sure taht there is no loss when i am saving my image
public void saveImage()
     File file3; // The file that the user wants to save.
JFileChooser fd; // File dialog that lets the user specify the file.
fd = new JFileChooser(".");
fd.setDialogTitle("Save Image As TIFF...");
int action = fd.showSaveDialog(this);
if (action != JFileChooser.APPROVE_OPTION) {
file3 = fd.getSelectedFile();
if (file3.exists()) {
// If file already exists, ask before replacing it.
action = JOptionPane.showConfirmDialog(this,
"Replace existing file?");
if (action != JOptionPane.YES_OPTION)
try {
FileOutputStream os = new FileOutputStream(file3);
TIFFEncodeParam param1 = new TIFFEncodeParam();// USE WHEN CONVERTING TO TIFF FILE
     //param1.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4); //USE IF BINARY IMAGE
     //param1.setCompression(TIFFEncodeParam.COMPRESSION_NONE);//USE IF BINARY IMAGE
     //param1.setCompression(TIFFEncodeParam.COMPRESSION_LZW); //USE IF BINARY IMAGE
ImageEncoder enc =ImageCodec.createImageEncoder("TIFF",os,param1);
catch (IOException e)
               // Some error has occurred while trying to write.
               //Show an error message.
                              "Sorry, an error has occurred:\n" + e.getMessage());
Any suggestions ?


Could you find any method to change the tiff image compression or even resolution.
When i try this,
String filename="c:\\sample1.tif";      
          File file = new File(filename);
     SeekableStream s = new FileSeekableStream(file);
     ImageDecoder dec = ImageCodec.createImageDecoder("TIFF", s, null);
     //RenderedImage op = new NullOpImage(dec.decodeAsRenderedImage(), null,null, OpImage.OP_COMPUTE_BOUND);
     RenderedImage op = new NullOpImage(dec.decodeAsRenderedImage(0),null,null,OpImage.OP_IO_BOUND);
     ByteArrayOutputStream output = new ByteArrayOutputStream();
     TIFFEncodeParam tp=new TIFFEncodeParam();
     ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF", output, tp);
     byte compressedData[] = output.toByteArray();
     FileOutputStream fouts=new FileOutputStream("c:\\sample2.tif");
It's giving errro saying that "End of data reached before next EOL encountered" when i call encoder.encode(op);
any suggestions?????

Read other 5 answers


Related Articles

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.764 s.