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

[3107 byte] By [raf2003a] at [2007-11-26 14:29:17]
# 1
Which java release this is on?Did you try jdk6?Thanks, Dmitri
dmitri_trembovetskia at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 2

This is Java 5. I really don't want to have to move to Java 6 for this. My users will then all have to upgrade, and that will be a pain in the (explative deleted).

These are all grayscale images with a component color model of 8bit pixel depth and TYPE_BYTE data buffer. This brightness issue only seems to happen when I use the rendering hint INTERPOLATION_NEAREST_NEIGHBOR or no rendering hints at all. If I use either of the other interpolation methods, it is always showing the image as brighter. This is a problem because these are medical images. I can't have any distortion of the image.

Thanks,

Rafael

raf2003a at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 3

> This is a problem because these are medical images.

>I can't have any distortion of the image.

OOPS !

I remember a time when Java licence said it was not intended for medical nor aircraft embedded applications... No wit is only forbiden to create Java apps for nuclear purpose "You acknowledge that

Licensed Software is not designed or intended for use

in the design, construction, operation or maintenance

of any nuclear facility"

OMG ! is Nuclear Magnetic Resonance Imaging a "nuclear facility" ?

Kilwcha at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 4
This is not a problem..... This is not a diagnostic utility. Rather it is designed for case review and teaching. My worry about the image not looking right is more about my ability to look cool, than worry about a missed diagnosis.
raf2003a at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 5

Is the whole screen brighter or just the image? Could it be that when the CPU usage is increased the screen is brighter?

You could try using the drawImage that takes in the AffineTransform as a parameter. That way you don't have to use 2 different drawImage methods. Potentially that will make the image brightness consistently bright.

rkippena at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 6

I worked on this a little when you first posted the question but was uable to use your

code snippets to get anything to work properly. So I'll ask some questions.

1 — What size are these images you are showing? Does the size vary with different

images?

2 — What size is your offScreenImage and do you calculate it for any/each image? Or,

how does the size of the image and the offScreenImage relate?

3 — These two statements are confusing to me:

This brightness issue only seems to happen when I use the rendering hint

INTERPOLATION_NEAREST_NEIGHBOR or no rendering hints at all. If I use either of the other

interpolation methods, it is always showing the image as brighter.

So the image is shown brighter under the following conditions:

no rendering hints are used

INTERPOLATION_NEAREST_NEIGHBOR

VALUE_INTERPOLATION_BICUBIC

VALUE_INTERPOLATION_BILINEAR?

4 — What is/are the increment(s) of rotation (eg, 90 degrees)?

5 — Are you using the original, source image in every transformed rendering or do

you make a new BufferedImage for each/some rendering(s)?

There are so many ways to get into trouble with these things. If you post some workable

code that demonstrates the trouble it might be easier to find the trouble and/or fix it.

Otherwise, we're left with trying to figure out what you might be trying to do and how you

got into trouble doing it.

crwooda at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 7
In addition to these questions - what type of buffered image are you using and how you create it?
neigora at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 8
The good (or bad) news is that this bug is fixed in Java 6. Not much use if you have to use Java 5 though. I couldn't find a corresponding entry in the bug database, so I don't know whether there's a workaround or not.
pal20a at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 9

The bug was fixed in jdk6 as a side-effect of this fix:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5051527

Basically, in most cases now we go through a different code path which doesn't have the issues you noticed.

This means that unfortunately there is no real work around in 5.0.

Thanks,

Dmitri

dmitri_trembovetskia at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...
# 10

Yes, It does seem like I will be switching to Java 6. Especially since it also fixed another bug I've noticed. For whatever reason, some versions of Windows XP will not fully respect the arguments passed to Java Web Start in a JNLP file. Once I upgraded to Java 6, this problem has been corrected.

Thanks everyone for your help

raf2003a at 2007-7-8 2:23:35 > top of Java-index,Security,Cryptography...