MCPcopy Create free account
hub / github.com/PCGen/pcgen / adjustRectToFitImage

Method adjustRectToFitImage

code/src/java/pcgen/gui2/tools/Utility.java:168–193  ·  view source on GitHub ↗

Adjust the crop rectangle to fit within the image it is cropping. Also ensure the area is square. @param image The image being cropped @param cropRect The rectangle defining the cropping area. This may be updated.

(RenderedImage image, Rectangle cropRect)

Source from the content-addressed store, hash-verified

166 * @param cropRect The rectangle defining the cropping area. This may be updated.
167 */
168 public static void adjustRectToFitImage(RenderedImage image, Rectangle cropRect)
169 {
170 // Make sure the rectangle is not too big
171 if (cropRect.width > image.getWidth())
172 {
173 cropRect.width = image.getWidth();
174 }
175 if (cropRect.height > image.getHeight())
176 {
177 cropRect.height = image.getHeight();
178 }
179
180 // Make it square
181 int dimension = Math.min(cropRect.width, cropRect.height);
182 cropRect.setSize(dimension, dimension);
183
184 // Now adjust the origin point so the box is within the image
185 if ((cropRect.x + cropRect.width) > image.getWidth())
186 {
187 cropRect.x = image.getWidth() - cropRect.width;
188 }
189 if ((cropRect.y + cropRect.height) > image.getHeight())
190 {
191 cropRect.y = image.getHeight() - cropRect.height;
192 }
193 }
194
195 /**
196 * Trim a string from the left to fit within the specified width.

Callers 4

referenceChangedMethod · 0.95
mouseDraggedMethod · 0.95
mouseWheelMovedMethod · 0.95
stateChangedMethod · 0.95

Calls 2

setSizeMethod · 0.65
minMethod · 0.45

Tested by

no test coverage detected