(String path)
| 19 | ImagePlus imp; |
| 20 | |
| 21 | public void run(String path) { |
| 22 | imp = WindowManager.getCurrentImage(); |
| 23 | if (imp==null) { |
| 24 | IJ.noImage(); |
| 25 | return; |
| 26 | } |
| 27 | if (path.equals("")) { |
| 28 | SaveDialog sd = new SaveDialog("Save as PNG...", imp.getTitle(), ".png"); |
| 29 | String name = sd.getFileName(); |
| 30 | if (name==null) |
| 31 | return; |
| 32 | String dir = sd.getDirectory(); |
| 33 | path = dir + name; |
| 34 | } |
| 35 | try { |
| 36 | writeImage(imp, path, Prefs.getTransparentIndex()); |
| 37 | } catch (Exception e) { |
| 38 | String msg = e.getMessage(); |
| 39 | if (msg==null || msg.equals("")) |
| 40 | msg = ""+e; |
| 41 | msg = "An error occured writing the file.\n \n" + msg; |
| 42 | if (msg.contains("NullPointerException")) |
| 43 | msg = "Incorrect file path:"; |
| 44 | msg += "\n \n"+path; |
| 45 | IJ.error("PNG Writer", msg); |
| 46 | } |
| 47 | IJ.showStatus(""); |
| 48 | } |
| 49 | |
| 50 | public void writeImage(ImagePlus imp, String path, int transparentIndex) throws Exception { |
| 51 | if (imp.getType()==ImagePlus.COLOR_256) { |
nothing calls this directly
no test coverage detected