Image gets brighter when AffineTransform is applied
I need help. I am drawing an image on the Graphics object of an offscreen image (back buffer). When I draw the image using the default transform there is not problem, however as soon as a rotate or flip the image it gets brighter. Not sure why.
Here is my code:
if (this.viewer.isTransformed())
{
System.out.println("IS TRANSFORMED");
AffineTransform trans = this.backG.getTransform();
// get new transform
this.backG.setTransform(getImageTransform(this.backG));
this.backG.drawImage(img, x, y, this.displayedImgWidth,
this.displayedImgHeight,null);
// revert to old transform
this.backG.setTransform(trans);
}
else
{
this.backG.drawImage(img, x, y, this.displayedImgWidth,
this.displayedImgHeight,this);
}
Here is my get transform code:
public AffineTransform getImageTransform(Graphics2D g)
{
AffineTransform transform = g.getTransform();
if (this.viewer.flipHorizontal && this.viewer.flipVertical)
{
transform =
AffineTransform.getTranslateInstance(this.offScreenImage.getWidth(),
this.offScreenImage.getHeight());
transform.concatenate(AffineTransform.getScaleInstance(-1, -1));
}
elseif (this.viewer.flipHorizontal)
{
transform =
AffineTransform.getTranslateInstance(this.offScreenImage.getWidth(),
0);
transform.concatenate(AffineTransform.getScaleInstance(-1, 1));
}
elseif (this.viewer.flipVertical)
{
transform = AffineTransform.getTranslateInstance(0,
this.offScreenImage.getHeight());
transform.concatenate(AffineTransform.getScaleInstance(1, -1));
}
if ((this.viewer.rotate % 360) != 0)
{
double theta = Math.toRadians(this.viewer.rotate);
double cx = this.offScreenImage.getWidth() / 2;
double cy = this.offScreenImage.getHeight() / 2;
transform.preConcatenate(AffineTransform.getRotateInstance(theta,
cx, cy));
}
return transform;
}
Any help is appreciated.
Message was edited by:
raf2003

