Saves the stack as a multi-image TIFF using the specified path. Equivalent to IJ.saveAsTiff(imp,path), which is more convenient.
(String path)
| 181 | /** Saves the stack as a multi-image TIFF using the specified path. |
| 182 | Equivalent to IJ.saveAsTiff(imp,path), which is more convenient. */ |
| 183 | public boolean saveAsTiffStack(String path) { |
| 184 | if (fi.nImages==1) { |
| 185 | error("This is not a stack"); |
| 186 | return false; |
| 187 | } |
| 188 | boolean virtualStack = imp.getStack().isVirtual(); |
| 189 | if (virtualStack) |
| 190 | fi.virtualStack = (VirtualStack)imp.getStack(); |
| 191 | fi.info = imp.getInfoProperty(); |
| 192 | fi.description = getDescriptionString(); |
| 193 | if (virtualStack) { |
| 194 | FileInfo ofi = imp.getOriginalFileInfo(); |
| 195 | if (path!=null && ofi!=null && path.equals(ofi.directory+ofi.fileName)) { |
| 196 | error("TIFF virtual stacks cannot be saved in place."); |
| 197 | return false; |
| 198 | } |
| 199 | String[] labels = null; |
| 200 | ImageStack vs = imp.getStack(); |
| 201 | for (int i=1; i<=vs.getSize(); i++) { |
| 202 | String label = vs.getSliceLabel(i); |
| 203 | if (i==1 && label==null) |
| 204 | break; |
| 205 | if (labels==null) |
| 206 | labels = new String[vs.getSize()]; |
| 207 | labels[i-1] = label; |
| 208 | } |
| 209 | fi.sliceLabels = labels; |
| 210 | } else |
| 211 | fi.sliceLabels = imp.getStack().getSliceLabels(); |
| 212 | fi.roi = RoiEncoder.saveAsByteArray(imp.getRoi()); |
| 213 | fi.overlay = getOverlay(imp); |
| 214 | fi.properties = imp.getPropertiesAsArray(); |
| 215 | if (imp.isComposite()) saveDisplayRangesAndLuts(imp, fi); |
| 216 | DataOutputStream out = null; |
| 217 | try { |
| 218 | TiffEncoder file = new TiffEncoder(fi); |
| 219 | out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path),bsize)); |
| 220 | file.write(out); |
| 221 | out.close(); |
| 222 | } catch (IOException e) { |
| 223 | showErrorMessage("saveAsTiffStack", path, e); |
| 224 | return false; |
| 225 | } finally { |
| 226 | if (out!=null) |
| 227 | try {out.close();} catch (IOException e) {} |
| 228 | } |
| 229 | updateImp(fi, FileInfo.TIFF); |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | /** Converts this image to a TIFF encoded array of bytes, |
| 234 | which can be decoded using Opener.deserialize(). */ |
no test coverage detected