3 import ij.plugin.filter.*;
14 boolean zeroFill =
Prefs.
get(
"resizer.zero",
false);
16 public void run(String arg) {
17 int wOld, hOld, wNew, hNew;
20 wOld = imp.getWidth();
21 hOld = imp.getHeight();
23 String[] sPositions = {
24 "Top-Left",
"Top-Center",
"Top-Right",
25 "Center-Left",
"Center",
"Center-Right",
26 "Bottom-Left",
"Bottom-Center",
"Bottom-Right"
29 String strTitle =
"Resize Image Canvas";
30 GenericDialog gd =
new GenericDialog(strTitle);
31 gd.addNumericField(
"Width:", wOld, 0, 5,
"pixels");
32 gd.addNumericField(
"Height:", hOld, 0, 5,
"pixels");
33 gd.addChoice(
"Position:", sPositions, sPositions[4]);
34 gd.addCheckbox(
"Zero Fill", zeroFill);
39 wNew = (int)gd.getNextNumber();
40 hNew = (int)gd.getNextNumber();
41 int iPos = gd.getNextChoiceIndex();
42 zeroFill = gd.getNextBoolean();
46 int xC = (wNew - wOld)/2;
47 int xR = (wNew - wOld);
48 int yC = (hNew - hOld)/2;
49 int yB = (hNew - hOld);
53 xOff=0; yOff=0;
break;
55 xOff=xC; yOff=0;
break;
57 xOff=xR; yOff=0;
break;
59 xOff=0; yOff=yC;
break;
61 xOff=xC; yOff=yC;
break;
63 xOff=xR; yOff=yC;
break;
65 xOff=0; yOff=yB;
break;
67 xOff=xC; yOff=yB;
break;
69 xOff=xR; yOff=yB;
break;
71 xOff=xC; yOff=yC;
break;
74 Undo.setup(
Undo.COMPOUND_FILTER, imp);
75 ImageProcessor newIP = expandImage(imp.
getProcessor(), wNew, hNew, xOff, yOff);
77 Undo.setup(
Undo.COMPOUND_FILTER_DONE, imp);
80 public ImageProcessor expandImage(ImageProcessor ipOld,
int wNew,
int hNew,
int xOff,
int yOff) {
81 ImageProcessor ipNew = ipOld.createProcessor(wNew, hNew);
85 ipNew.setColor(Toolbar.getBackgroundColor());
87 ipNew.insert(ipOld, xOff, yOff);