I made a methode to rotate a image (most code found in stackoverflow's nice answers). Now I need to cut the image: (1) by the outline and (2) inline the image (no border shown). But I don't know how to do that and I found no sample in all answers here. Is it possible to get the coordinates (all four edge points) from the rotated image somehow? Thanks for help.
public static BufferedImage rotateTest(BufferedImage image, double degrees) {
// --- get image size
int w = image.getWidth();
int h = image.getHeight();
// --- need longest side
int m = w;
if (h > w) {
m = h;
}
// --- double length for rotating
m = m * 2;
// --- rotate component
BufferedImage result = new BufferedImage(m, m, image.getType());
Graphics2D g = (Graphics2D) result.getGraphics();
// --- create transform
AffineTransform transformer = new AffineTransform();
// --- translate it to the center of the component
transformer.translate(result.getWidth() / 2, result.getHeight() / 2);
// --- do the actual rotation
transformer.rotate(Math.toRadians(degrees));
// --- translate the object so that you rotate it around the center
transformer.translate(-image.getWidth() / 2, -image.getHeight() / 2);
// --- anti aliasing
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// --- drawing
g.drawImage(image, transformer, null);
// --- done
g.dispose();
// --- cut to outline
// --- run out
return result;
}