用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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:45:16  来源:igfitidea点击:

Adjust brightness and contrast of BufferedImage in Java

javagraphicsimage-processing

提问by a paid nerd

I'm processing a bunch of images with some framework, and all I'm given is a bunch of BufferedImageobjects. 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 scaleFactorof 1.2 and offsetof 15 seems to make the image about a stop brighter.

scaleFactor1.2 和offset15 的A似乎使关于停止的图像更亮。

Yay!

好极了!

Read more in the docs for RescaleOp.

文档中RescaleOp阅读更多信息。