Ich verwende folgene Routiene zum drehen eines Bildes:
Das ist der Aufruf:
Verwende ich kleine Bilder, funktioniert es ohne Probleme. Bei großen kommt die Exception.
Hat jemand eine Idee wieso?
Code:
static BufferedImage tilt(BufferedImage src, double angle) {
int w = src.getWidth(), h = src.getHeight();
int newW = (int)(Math.round(h * Math.abs(Math.sin(angle))+w * Math.abs(Math.cos(angle))));
int newH = (int)(Math.round(h * Math.abs(Math.cos(angle))+w * Math.abs(Math.sin(angle))));
AffineTransform at = AffineTransform.getTranslateInstance((newW-w)/2,(newH-h)/2);
at.rotate(angle, w/2, h/2);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage dst = gc.createCompatibleImage(newW, newH);
Graphics2D g = dst.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setPaint(Color.MAGENTA);
g.fillRect(0,0,newW,newH);
g.drawRenderedImage(src, at);
g.dispose();
return dst;
}
Das ist der Aufruf:
Code:
private void jLabelDrehenRechtsMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if(bBildGeladen)
{
dWinkelAktuell = dWinkelAktuell + dWinkelZumVerstellen;
if(dWinkelAktuell > 360)
dWinkelAktuell = 360 -dWinkelAktuell;
ImgOriginal = tilt(buffImgOriginal, Math.toRadians(dWinkelAktuell));
int iTempWidth = ImgOriginal.getWidth(null);
int iTempHeight = ImgOriginal.getHeight(null);
double dVerhaeltnis = (double)iTempWidth/(double)iTempHeight;
iGlobHeight = (int) (iGlobWidth / dVerhaeltnis);
repaint();
}
}
Verwende ich kleine Bilder, funktioniert es ohne Probleme. Bei großen kommt die Exception.
Hat jemand eine Idee wieso?