Save the stack as raw data using the specified path.
(String path)
| 528 | |
| 529 | /** Save the stack as raw data using the specified path. */ |
| 530 | public boolean saveAsRawStack(String path) { |
| 531 | if (fi.nImages==1) |
| 532 | {IJ.log("This is not a stack"); return false;} |
| 533 | fi.intelByteOrder = Prefs.intelByteOrder; |
| 534 | boolean signed16Bit = false; |
| 535 | Object[] stack = null; |
| 536 | int n = 0; |
| 537 | boolean virtualStack = imp.getStackSize()>1 && imp.getStack().isVirtual(); |
| 538 | if (virtualStack) { |
| 539 | fi.virtualStack = (VirtualStack)imp.getStack(); |
| 540 | if (imp.getProperty("AnalyzeFormat")!=null) fi.fileName="FlipTheseImages"; |
| 541 | } |
| 542 | OutputStream out = null; |
| 543 | try { |
| 544 | signed16Bit = imp.getCalibration().isSigned16Bit(); |
| 545 | if (signed16Bit && !virtualStack) { |
| 546 | stack = (Object[])fi.pixels; |
| 547 | n = imp.getWidth()*imp.getHeight(); |
| 548 | for (int slice=0; slice<fi.nImages; slice++) { |
| 549 | short[] pixels = (short[])stack[slice]; |
| 550 | for (int i=0; i<n; i++) |
| 551 | pixels[i] = (short)(pixels[i]-32768); |
| 552 | } |
| 553 | } |
| 554 | ImageWriter file = new ImageWriter(fi); |
| 555 | out = new BufferedOutputStream(new FileOutputStream(path),bsize); |
| 556 | file.write(out); |
| 557 | out.close(); |
| 558 | } catch (IOException e) { |
| 559 | showErrorMessage("saveAsRawStack", path, e); |
| 560 | return false; |
| 561 | } finally { |
| 562 | if (out!=null) |
| 563 | try {out.close();} catch (IOException e) {} |
| 564 | } |
| 565 | if (signed16Bit) { |
| 566 | for (int slice=0; slice<fi.nImages; slice++) { |
| 567 | short[] pixels = (short[])stack[slice]; |
| 568 | for (int i=0; i<n; i++) |
| 569 | pixels[i] = (short)(pixels[i]+32768); |
| 570 | } |
| 571 | } |
| 572 | updateImp(fi, fi.RAW); |
| 573 | return true; |
| 574 | } |
| 575 | |
| 576 | /** Save the image as comma or tab-delimited text using a save |
| 577 | file dialog. Returns false if the user selects cancel. */ |
no test coverage detected