How to change the brightness of an Image

前端 未结 4 515
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 01:42

My Question: I want to be able to change the brightness of a resource image and have three instances of it as ImageIcons. One at 50% brightness (so darker), ano

4条回答
  •  情深已故
    2021-02-06 01:56

    The doc says:

    The pseudo code for the rescaling operation is as follows:

    for each pixel from Source object {
        for each band/component of the pixel {
            dstElement = (srcElement*scaleFactor) + offset
        }
    }
    

    It's just a linear transformation on every pixel. The parameters for that transformation are scaleFactor and offset. If you want 100% brightness, this transform must be an identity, i.e. dstElement = srcElement. Setting scaleFactor = 1 and offset = 0 does the trick.

    Now suppose you want to make the image darker, at 75% brightness like you say. That amounts to multiplying the pixel values by 0.75. You want: dstElement = 0.75 * srcElement. So setting scaleFactor = 0.75 and offset = 0 should do the trick. The problem with your values is that they go from 0 to 100, you need to use values between 0 and 1.

提交回复
热议问题