0

I want to change the "brightness" of an NSImage.

I've searched a bit around but I found nothing really helpful...

So, what is the easiest, Cocoa-friendly way to do that?

2
  • the silly way to do it would be to increase the rgb values of each pixel (not going over 255) but I bet there are Quartz filters to do this.
    – Ali
    Mar 25, 2012 at 10:09
  • 1
    tint the image with more white balance? stackoverflow.com/questions/1413135/…
    – amleszk
    Mar 25, 2012 at 11:03

2 Answers 2

7

You can do it with Core Image Filters. But You need to use CIImage not NSImage so You will need to convert it. Here is CIFilter Reference with all filters. Take a look at "CIColorControls" it will let You achieve what You want.

CIColorControls

Adjusts saturation, brightness, and contrast values.

Parameters

inputImage (A CIImage class whose display name is Image).

inputSaturation (An NSNumber class whose attribute type is CIAttributeTypeScalar and whose display name is Saturation. Default value: 1.00 Minimum: 0.00 Maximum: 2.00 Slider minimum: 0.00 Slider maximum: 2.00 Identity: 1.00)

inputBrightness (An NSNumber class whose attribute type is CIAttributeTypeScalar and whose display name is Brightness. Default value: 0.00 Minimum: -1.00 Maximum: 1.00 Slider minimum: -1.00 Slider maximum: 1.00 Identity: 0.00)

inputContrast (An NSNumber class whose attribute type is CIAttributeTypeScalar and whose display name is Contrast. Default value: 1.00 Minimum: 0.00 Maximum: 4.00 Slider minimum: 0.00 Slider maximum: 4.00 Identity: 1.00)

2
  • Justin - did they change the documentation? What you have listed above is different from what's in the documents, IE it doesn't list the minimum and maximum values. Or did you get that from somewhere else?
    – Ser Pounce
    Jan 29, 2013 at 19:35
  • @CoDEFRo I get it from Apple developer library from link to reference. They have changed documentation.
    – Justin Boo
    Jan 29, 2013 at 20:09
1

You can use coreImage. Take a look at Core Image Fun House application code.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.