java - How to make an image zoom with respect to its frame (ImageJ) -


so thought ask new question extension of old question. able contents out imagej window jinternal frame inside desktop pane. image not zoom frames size enlarged. have found couple of ways using zoom class in imagej not scale fit frame. wondering if knows doing wrong. zoom in working , zoom out set zoom , scale zoom don't work , have no idea why. thank in advance.

here part of code:

public class customgui extends imagewindow implements internalframelistener, componentlistener, actionlistener{      public customgui(imageplus imp, string title, jdesktoppane desktop, final jmenuitem save, jwindow win, jmenuitem fft) {         super(imp);         // todo auto-generated constructor stub         setcall();         img = imp;         save.setenabled(true);         fft.setenabled(true);         //this.title = title;         this.win = win;         this.fft = fft;         this.save = save;           jpanel panel = new jpanel();          imagecanvas c = new imagecanvas(imp);         c.getimage();          //panel2.add(new jlabel(new imageicon(c.getimage())));          m = new imagewindow(img);          image n = new image();         frame = new myinternalframe(title, img, save,m);         //imagecanvas c = m.getcanvas();         imageplus im = new imageplus();         im.setimage(img);           //imageroi roi = imageroi();         //panel.add(c);        //   frame.add(m.getcontentpane());         m.centernextimage();        //this try use zoom class.         img.getcanvas().setscaletofit(true);          //imagecanvas nu = new imagecanvas(img);         //nu.setscaletofit(true);       //i set arg "scale" doesn't work, when put in component resized listener.         zoom z = new zoom(img);         string arg = "orig";         z.run(arg);          //m.setlocationrelativeto(frame);         //m.setlocationandsize(true);         //m.setlocationandsize(frame.getwidth(), frame.getheight(), frame.getwidth(), frame.getheight());         panel.add(m.getcanvas());         panel.setbackground(color.white);          frame.add(panel);         frame.setvisible(true);          frame.setautoscrolls(true);         frame.setautoscrolls(true);         desktop.add(frame);         try {                 frame.setselected(true);         } catch (java.beans.propertyvetoexception e) {          }        frame.addinternalframelistener(this);          frame.addcomponentlistener(this);        //win.add(desktop);      }      public void actionperformed(actionevent e){         if(e.getactioncommand().equals(show)){             save.setenabled(true);             frame.addinternalframelistener(this);         }          system.out.println("beingg called");     }        public void setcall(){             called = true;         }          public void setcallf(){         called = false;         }          public boolean getcall(){         return called;         }          //this internal frame resized.     @override     public void componentresized(componentevent arg0) {         // todo auto-generated method stub         rectangle r = frame.getbounds();     //      int h = (int) r.getheight();     //      int w = (int) r.getwidth();     //      m.resize(w, h);         //m.getcanvas().unzoom();         //m.setlocationandsize((int)r.getwidth(), (int)r.getheight(), (int)r.getwidth(), (int)r.getheight());         m.getcanvas().fittowindow(r);         system.out.println("resized- real one");      }      @override     public void componentshown(componentevent arg0) {         // todo auto-generated method stub         frame.show();      }      } 

i added constructor zoom class (this part of zoom class):

    /** plugin implements commands in image/zoom submenu. */    public class zoom implements plugin{  imageplus imp; public zoom (imageplus img){     imp = img; }  public void run(string arg) {     //imageplus imp = windowmanager.getcurrentimage();     //imageplus imp = img;     if (imp==null)         {ij.noimage(); return;}     imagecanvas ic = imp.getcanvas();     if (ic==null) return;     point loc = ic.getcursorloc();     if (!ic.cursoroverimage()) {         rectangle srcrect = ic.getsrcrect();         loc.x = srcrect.x + srcrect.width/2;         loc.y = srcrect.y + srcrect.height/2;     }     int x = ic.screenx(loc.x);     int y = ic.screeny(loc.y);     if (arg.equals("in")) {         ic.zoomin(x, y);         if (ic.getmagnification()<=1.0) imp.repaintwindow();     } else if (arg.equals("out")) {         ic.zoomout(x, y);         if (ic.getmagnification()<1.0) imp.repaintwindow();     } else if (arg.equals("orig"))         ic.unzoom();     else if (arg.equals("100%"))         ic.zoom100percent();     else if (arg.equals("to"))         zoomtoselection(imp, ic);     else if (arg.equals("set"))         setzoom(imp, ic);     else if (arg.equals("max")) {         imagewindow win = imp.getwindow();         win.setbounds(win.getmaximumbounds());         win.maximize();     } if (arg.equals("scale"))         scaletofit(imp); } 

in zoom.java, don't see constructor taking argument. sure you're importing , using ij.plugin.zoom?

the standard imagej gui allows fit scale using ij.plugin.zoom class. run following javascript snippet in fiji's script editor switch between normal , scale fit modes:

zm = new zoom(); zm.run("scale"); 

the status bar of imagej main window (and source of zoom.java) provides hint pressing alt while resizing window result in image scaling window size.

sorry don't spend time fiddling code: it's not minimal example.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -