Hello folks,
Currently I am working on a plugin for ImageJ but I've gotten a bit stuck. I want to get the value of height and width of the currently selected window but I'm having some problems. Currently what my code looks like is this: String s2_strWidth = null; String s2_strHeight = null; int s2_width = 0; int s2_height = 0; s2_strWidth = IJ.runMacro("getWidth();"); if(s2_strWidth != null) { s2_width = Integer.valueOf(s2_strWidth); IJ.log("Wait what's going on"); } else { IJ.log("You are throwing an exception at s2_strWidth"); return; } s2_strHeight = IJ.runMacro("getHeight();"); if(s2_strHeight != null) { s2_height = Integer.valueOf(s2_strHeight); IJ.log("Wait what's going on"); } else { IJ.log("You are throwing an exception at getHeight"); return; } However, s2_strWidth and s2_strHeight are always returning null so I cannot physically get the value right now. I'm sure that I am missing something here that I need to get the values that I need. Can someone see what I am missing? Or is there a better way of trying to use IJ.runMacro ? |
Hi,
this is a strange way to get the dimension of an image. Why not use the IJ API [1], instead of running macros? ImagePlus imp = IJ.getImage(); int w = imp.getWidth(); int h = imp.getHeight(); Best regards Michael [1]: http://javadoc.imagej.net/ImageJ1/ All API docs: http://javadoc.imagej.net/ On 07.02.2017 19:27, Potterd2 wrote: > Hello folks, > > Currently I am working on a plugin for ImageJ but I've gotten a bit stuck. I > want to get the value of height and width of the currently selected window > but I'm having some problems. Currently what my code looks like is this: > > String s2_strWidth = null; > String s2_strHeight = null; > int s2_width = 0; > int s2_height = 0; > s2_strWidth = IJ.runMacro("getWidth();"); > if(s2_strWidth != null) { > s2_width = Integer.valueOf(s2_strWidth); > IJ.log("Wait what's going on"); > } > else { > IJ.log("You are throwing an exception at s2_strWidth"); > return; > } > s2_strHeight = IJ.runMacro("getHeight();"); > if(s2_strHeight != null) { > s2_height = Integer.valueOf(s2_strHeight); > IJ.log("Wait what's going on"); > } > else { > IJ.log("You are throwing an exception at getHeight"); > return; > } > > However, s2_strWidth and s2_strHeight are always returning null so I cannot > physically get the value right now. I'm sure that I am missing something > here that I need to get the values that I need. Can someone see what I am > missing? Or is there a better way of trying to use IJ.runMacro ? > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Retrieving-value-from-IJ-runMacro-tp5018046.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |