1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
public void paintComponent(Graphics g) {
super.paintComponent(g); // paint background
if (image == null) {
return;
}
Graphics2D g2 = (Graphics2D) g;
//********** gestion roation image *******************//
AffineTransform origXform = g2.getTransform();
AffineTransform newXform = (AffineTransform)(origXform.clone());
//center of rotation is center of the panel
int xRot = this.getWidth()/2;
int yRot = this.getHeight()/2;
newXform.rotate(Math.toRadians(currentAngle), xRot, yRot);
g2.setTransform(newXform);
//draw image centered in panel
// int x = (getWidth() - image.getWidth(this))/2;
// int y = (getHeight() - image.getHeight(this))/2;
//*******************************************************//
double w = image.getWidth() *scaleWidth;
double h = image.getHeight() *scaleHeight;
Dimension dim = getSize();
double x = 0;
double y = 0;
if (dim.getWidth() > w) {
x = (dim.getWidth() - w)/2;
}
if (dim.getHeight() > h) {
y = (dim.getHeight() - h)/2;
}
g2.drawImage(image,(int)x,(int)y,(int)w,(int)h,this);
g2.setTransform(origXform); |
Partager