1 package ij.plugin.filter;
12 private static int newWidth = 100;
13 private static int newHeight = 100;
14 private static boolean constrain =
true;
15 private static boolean interpolate =
true;
18 crop = arg.equals(
"crop");
27 public void run(ImageProcessor ip) {
28 Roi roi = imp.getRoi();
29 if (roi!=null && roi.getType()>=Roi.LINE && roi.getType()<=Roi.FREELINE) {
30 IJ.
error(
"The Crop and Adjust->Size commands\ndo not work with line selections.");
33 boolean sizeToHeight=
false;
35 Rectangle bounds = roi.getBounds();
36 newWidth = bounds.width;
37 newHeight = bounds.height;
40 GenericDialog gd =
new GenericDialog(
"Resize",
IJ.
getInstance());
41 gd.addNumericField(
"Width (pixels):", newWidth, 0);
42 gd.addNumericField(
"Height (pixels):", newHeight, 0);
43 gd.addCheckbox(
"Constrain Aspect Ratio", constrain);
44 gd.addCheckbox(
"Interpolate", interpolate);
45 gd.addMessage(
"NOTE: Undo is not available");
49 newWidth = (int)gd.getNextNumber();
50 newHeight = (int)gd.getNextNumber();
51 if (gd.invalidNumber()) {
52 IJ.
error(
"Width or height are invalid.");
55 constrain = gd.getNextBoolean();
56 interpolate = gd.getNextBoolean();
57 sizeToHeight = constrain && newWidth==0;
58 if (newWidth<=0.0 && !constrain) newWidth = 50;
59 if (newHeight<=0.0) newHeight = 50;
62 Rectangle r = ip.getRoi();
63 double oldWidth = r.width;;
64 double oldHeight = r.height;
65 if (!crop && constrain) {
67 newWidth = (int)(newHeight*(oldWidth/oldHeight));
69 newHeight = (int)(newWidth*(oldHeight/oldWidth));
71 ip.setInterpolate(interpolate);
74 ip = ip.resize(newWidth, newHeight);
78 }
catch(OutOfMemoryError o) {