Skip to main content
gamedev.net
🔒 Locked

[java] Darken a BufferedImage

Started by H_o_p_s 3 replies 2k views
Original Post
H_o_p_s
H_o_p_s
I know that there is a way to do this, but I can't make my way through the AffineTransform to get it working... if anyone has a quick code snippet they could post it would be wonderfull. Thanks!
BRING BACK THE BLACK (or at least something darker)
n0rmanfreak
n0rmanfreak
hi h_o_p_s

affineTransformation seems to be the wrong way as it's working only a coordinates not on color values.. i'm not sure if this can be done with the colorConvert class... a straight forward approch would be to loop through all pixels and set there rgbValue to (getRgb * alpha) where alpha is a number between 0 and 1 representing the darkening you want to achieve..

hope this helps..

i'll took a deeper look into that colorConvert...maybe i'll find something useful

good luck!
stormrunner
stormrunner
This seems to be what you seek. FYI, that site is a great resource for such things. If you didn't want to read, here's the relevant snippet :

// Darken the image by 10%float scaleFactor = .9f; // out of 100 ... obviouslyRescaleOp op = new RescaleOp(scaleFactor, 0, null);bufferedImage = op.filter(bufferedImage, null);

Yeah, "RescaleOp" is a bit misleading, but it does what you want [grin].
stormrunner
H_o_p_s
H_o_p_s
Thanks! Worked like a charm. I went to rate++ both of you but I have found that you are both already maxed... hehe.. thanks for all the help!
BRING BACK THE BLACK (or at least something darker)
H_o_p_s
H_o_p_s
Here is what shading got me:


Notice the shading difference between the top and bottom layer. All from one graphic on the HD [smile]
BRING BACK THE BLACK (or at least something darker)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.