Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
export image file in java from COMSOL and also plotting while solving
Posted Jul 31, 2012, 10:30 a.m. EDT 1 Reply
Please login with a confirmed email address before reporting spam
I am running a bunch of 1 hour time dependent COMSOL models in a big 'for' loop. I can get Eclipse to export a .txt file for each iteration of the 'for' loop and I can show a progress bar and a 2D/3D image at the end inside a the GUI (this is the GUI in the back of the API guide) Comsol provides for eclipse. I am having 2 problems though:
1) I can not get COMSOL to export an image file. The line of code:
model.result().export("plot1").run();
works for exporting .txt, but using:
model.result().export("img1").run();
does NOT work for exporting an image file. nothing appears.
I added the code:
BufferedImage bi = new BufferedImage(pWidth,pHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
frame.paint(g);
g.dispose();
try{ImageIO.write(bi,"png",new File("C:\\Users\\Alex\\Desktop\\surf_"+i+".png"));}catch (Exception e) {}
and I can get a screenshot of the JFrame of the GUI at the end of each time simulation but not the 2D plot that shoud appear (see attached file).
Anyone have hints how to make the export feature work for COMSOL and an image or how to take a screenshot with the 2D image in the JFrame?
2)
In that same GUI, what code and where do I need to add it to have the GUI display the solution as it happens?
model.sol("sol1").feature("t1").feature("fc1").set("plot", "on"); does not work, and:
model.sol("sol1").feature().create("t1","PlotWhileSolving") gives me the error:
com.comsol.util.exceptions.FlException: Operation cannot be created in this context
Thanks for any help
1) I can not get COMSOL to export an image file. The line of code:
model.result().export("plot1").run();
works for exporting .txt, but using:
model.result().export("img1").run();
does NOT work for exporting an image file. nothing appears.
I added the code:
BufferedImage bi = new BufferedImage(pWidth,pHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
frame.paint(g);
g.dispose();
try{ImageIO.write(bi,"png",new File("C:\\Users\\Alex\\Desktop\\surf_"+i+".png"));}catch (Exception e) {}
and I can get a screenshot of the JFrame of the GUI at the end of each time simulation but not the 2D plot that shoud appear (see attached file).
Anyone have hints how to make the export feature work for COMSOL and an image or how to take a screenshot with the 2D image in the JFrame?
2)
In that same GUI, what code and where do I need to add it to have the GUI display the solution as it happens?
model.sol("sol1").feature("t1").feature("fc1").set("plot", "on"); does not work, and:
model.sol("sol1").feature().create("t1","PlotWhileSolving") gives me the error:
com.comsol.util.exceptions.FlException: Operation cannot be created in this context
Thanks for any help
Attachments:
1 Reply Last Post Aug 3, 2012, 7:17 a.m. EDT