Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the ScreenGrabber class. Minor fixes to avoid some warnings. #190

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ij/Menus.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ InputStream getConfigurationFile(String jar) {
if (entry.getName().endsWith("plugins.config"))
return jarFile.getInputStream(entry);
}
jarFile.close();
}
catch (Throwable e) {
IJ.log(jar+": "+e);
Expand Down Expand Up @@ -971,6 +972,7 @@ InputStream autoGenerateConfigFile(String jar) {
sb.append(plugins + ", \""+name+"\", "+className+"\n");
}
}
jarFile.close();
}
catch (Throwable e) {
IJ.log(jar+": "+e);
Expand Down
4 changes: 2 additions & 2 deletions ij/gui/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,12 @@ public void setMaxIntervals(int intervals) {
/** Sets the length of the major tick in pixels.
* Call update() thereafter to make the change visible (if the image is shown already). */
public void setTickLength(int tickLength) {
tickLength = tickLength;
this.tickLength = tickLength;
}

/** Sets the length of the minor tick in pixels. */
public void setMinorTickLength(int minorTickLength) {
minorTickLength = minorTickLength;
this.minorTickLength = minorTickLength;
}

/** Sets the flags that control the axes format.
Expand Down
1 change: 0 additions & 1 deletion ij/gui/PlotVirtualStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class PlotVirtualStack extends VirtualStack {

public PlotVirtualStack(int width, int height) {
super(width, height);
this.bitDepth = bitDepth;
}

/** Adds a plot to the end of the stack. */
Expand Down
1 change: 0 additions & 1 deletion ij/gui/Toolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ void drawIcon(Graphics g, int tool, int x, int y) {
if (null==g) return;
icon = icons[tool];
if (icon==null) return;
this.icon = icon;
int x1, y1, x2, y2;
pc = 0;
if (icon.trim().startsWith("icon:")) {
Expand Down
59 changes: 38 additions & 21 deletions ij/plugin/ScreenGrabber.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package ij.plugin;

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import java.awt.image.MultiResolutionImage;

/** This plugin implements the Plugins/Utilities/Capture Screen
and Plugins/Utilities/Capture Image commands. Note that these
commands may not work on Linux if windows translucency or
special effects are enabled in the windows manager. */
/**
* This plugin implements the Plugins/Utilities/Capture Screen and
* Plugins/Utilities/Capture Image commands. Note that these commands may not
* work on Linux if windows translucency or special effects are enabled in the
* windows manager.
*/
public class ScreenGrabber implements PlugIn {
private static int delay = 10;

Expand All @@ -19,49 +23,62 @@ else if (arg.equals("delay"))
imp2 = captureDelayed();
else
imp2 = captureScreen();
if (imp2!=null)
if (imp2 != null)
imp2.show();
}

private ImagePlus captureDelayed() {
GenericDialog gd = new GenericDialog("Delayed Capture");
gd.addNumericField("Delay (seconds):", delay, 0);
gd.showDialog();
if (gd.wasCanceled())
return null;
int delay = (int)gd.getNextNumber();
if (delay<0) return null;
if (delay>60) delay=60;
for (int i=0; i<delay; i++) {
int delay = (int) gd.getNextNumber();
if (delay < 0)
return null;
if (delay > 60)
delay = 60;
for (int i = 0; i < delay; i++) {
IJ.wait(1000);
IJ.showStatus("Delayed capture: "+(i+1)+"/"+delay);
if (delay>4 && i==delay-2) IJ.beep();
IJ.showStatus("Delayed capture: " + (i + 1) + "/" + delay);
if (delay > 4 && i == delay - 2)
IJ.beep();
}
return captureScreen();
}


/** Captures the entire screen and returns it as an ImagePlus. */
public ImagePlus captureScreen() {
ImagePlus imp = null;
Image img=null;
try {
Robot robot = new Robot();
Rectangle r = GUI.getScreenBounds(IJ.getInstance()); // screen showing "ImageJ" window
Image img = robot.createScreenCapture(r);
if (img!=null) imp = new ImagePlus("Screenshot", img);
} catch(Exception e) {}

MultiResolutionImage mImage = robot.createMultiResolutionScreenCapture(r);
java.util.List<Image> resolutionVariants = mImage.getResolutionVariants();
if (resolutionVariants.size() > 1) {
img = resolutionVariants.get(1);
} else {
img = resolutionVariants.get(0);
}
if (img != null)
imp = new ImagePlus("Screenshot", img);
} catch (Exception e) {
}
return imp;
}

/** Captures the active image window and returns it as an ImagePlus. */
public ImagePlus captureImage() {
ImagePlus imp = IJ.getImage();
if (imp==null) {
if (imp == null) {
IJ.noImage();
return null;
}
ImageWindow win = imp.getWindow();
if (win==null) return null;
if (win == null)
return null;
win.toFront();
IJ.wait(500);
Point loc = win.getLocation();
Expand All @@ -77,14 +94,14 @@ public ImagePlus captureImage() {
try {
Robot robot = new Robot();
img = robot.createScreenCapture(r);
} catch(Exception e) { }
} catch (Exception e) {
}
ic.hideZoomIndicator(wasHidden);
if (img!=null) {
if (img != null) {
String title = WindowManager.getUniqueName(imp.getTitle());
imp2 = new ImagePlus(title, img);
}
return imp2;
}

}

1 change: 0 additions & 1 deletion ij/plugin/filter/BackgroundSubtracter.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ void buildRollingBall(double ballradius, int arcTrimPer) {
double smallballradius; // radius of rolling ball (downscaled in x,y and z when image is shrunk)
int halfWidth; // distance in x or y from center of patch to any edge (patch "radius")

this.shrinkFactor = shrinkFactor;
smallballradius = ballradius/shrinkFactor;
if (smallballradius<1)
smallballradius = 1;
Expand Down