Saves the image as a tab-delimited text file.
(DataOutputStream out)
| 27 | |
| 28 | /** Saves the image as a tab-delimited text file. */ |
| 29 | public void write(DataOutputStream out) throws IOException { |
| 30 | PrintWriter pw = new PrintWriter(out); |
| 31 | boolean calibrated = cal!=null && cal.calibrated(); |
| 32 | if (calibrated) |
| 33 | ip.setCalibrationTable(cal.getCTable()); |
| 34 | else |
| 35 | ip.setCalibrationTable(null); |
| 36 | boolean intData = !calibrated && ((ip instanceof ByteProcessor) || (ip instanceof ShortProcessor)); |
| 37 | int width = ip.getWidth(); |
| 38 | int height = ip.getHeight(); |
| 39 | int inc = height/20; |
| 40 | if (inc<1) inc = 1; |
| 41 | //IJ.showStatus("Exporting as text..."); |
| 42 | double value; |
| 43 | for (int y=0; y<height; y++) { |
| 44 | for (int x=0; x<width; x++) { |
| 45 | value = ip.getPixelValue(x,y); |
| 46 | if (intData) |
| 47 | pw.print((int)value); |
| 48 | else |
| 49 | pw.print(IJ.d2s(value, precision)); |
| 50 | if (x!=(width-1)) |
| 51 | pw.print(delimiter); |
| 52 | } |
| 53 | pw.println(); |
| 54 | if (y%inc==0) IJ.showProgress((double)y/height); |
| 55 | } |
| 56 | pw.close(); |
| 57 | IJ.showProgress(1.0); |
| 58 | //IJ.showStatus(""); |
| 59 | } |
| 60 | |
| 61 | public void setDelimiter(String delimiter) { |
| 62 | this.delimiter = delimiter; |
no test coverage detected