用Java调整BufferedImage的亮度和对比度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3433275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adjust brightness and contrast of BufferedImage in Java
提问by a paid nerd
I'm processing a bunch of images with some framework, and all I'm given is a bunch of BufferedImage
objects. Unfortunately, these images are really dim, and I'd like to brighten them up and adjust the contrast a little.
我正在用一些框架处理一堆图像,而我得到的只是一堆BufferedImage
对象。不幸的是,这些图像真的很暗,我想将它们调亮并稍微调整一下对比度。
Something like:
就像是:
BufferedImage image = something.getImage();
image = new Brighten(image).brighten(0.3); // for 30%
image = new Contrast(image).contrast(0.3);
// ...
Any ideas?
有任何想法吗?
采纳答案by a paid nerd
That was easy, actually.
这很容易,实际上。
RescaleOp rescaleOp = new RescaleOp(1.2f, 15, null);
rescaleOp.filter(image, image); // Source and destination are the same.
A scaleFactor
of 1.2 and offset
of 15 seems to make the image about a stop brighter.
scaleFactor
1.2 和offset
15 的A似乎使关于停止的图像更亮。
Yay!
好极了!
Read more in the docs for RescaleOp
.
在文档中RescaleOp
阅读更多信息。