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)
| 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. |
no test coverage detected