Skip to main content
HugoTW
Participating Frequently
November 1, 2017
Answered

Change New Color to Background/Foreground Color

  • November 1, 2017
  • 1 reply
  • 1238 views

Hello all,

I am working on Photoshop CC 2015 SDK. Does anyone know the function call or API to change the background or foreground color? C++ is preferred.

I am been searching this function for so long. Please help ^^

Thanks in advance.

This topic has been closed for replies.
Correct answer Tom Ruark

You need to be an automation plug-in for my code to work.

For a filter you can read the fore/back colors from the FilterRecord here: these are read only

FilterColor backColor; /**< The current background color, in the

                                     color space native to the image.*/

FilterColor foreColor; /**< The current foreground color, in the

                                     color space native to the image.*/

1 reply

Tom Ruark
Inspiring
November 2, 2017

You want an automation plug-in. See the Listener example. Here is code to set the foreground with a comment to set the background.

SPErr PlayeventSet(/*your parameters go here*/void)

{

     PIActionDescriptor result = NULL;

     DescriptorTypeID runtimeKeyID;

     DescriptorTypeID runtimeTypeID;

     DescriptorTypeID runtimeObjID;

     DescriptorTypeID runtimeEnumID;

     DescriptorTypeID runtimeClassID;

     DescriptorTypeID runtimePropID;

     DescriptorTypeID runtimeUnitID;

     SPErr error = kSPNoError;

     // Move this to the top of the routine!

     PIActionDescriptor desc0000000000000700 = NULL;

     error = sPSActionDescriptor->Make(&desc0000000000000700);

     if (error) goto returnError;

          // Move this to the top of the routine!

          PIActionReference ref00000000000002a0 = NULL;

          error = sPSActionReference->Make(&ref00000000000002a0);

          if (error) goto returnError;

// OR keyBackgroundColor

          error = sPSActionReference->PutProperty(ref00000000000002a0, classColor, keyForegroundColor);

          if (error) goto returnError;

     error = sPSActionDescriptor->PutReference(desc0000000000000700, keyNull, ref00000000000002A0);

     if (error) goto returnError;

          // Move this to the top of the routine!

          PIActionDescriptor desc0000000000000708 = NULL;

          error = sPSActionDescriptor->Make(&desc0000000000000708);

          if (error) goto returnError;

          error = sPSActionDescriptor->PutUnitFloat(desc0000000000000708, keyHue, unitAngle, 139.993);

          if (error) goto returnError;

          error = sPSActionDescriptor->PutFloat(desc0000000000000708, keySaturation, 61.5686);

          if (error) goto returnError;

          error = sPSActionDescriptor->PutFloat(desc0000000000000708, keyBrightness, 85.4902);

          if (error) goto returnError;

     error = sPSActionDescriptor->PutObject(desc0000000000000700, keyTo, classHSBColor, desc0000000000000708);

     if (error) goto returnError;

     // Unicode String as UTF8: photoshopPicker

     error = sPSActionDescriptor->PutString(desc0000000000000700, keySource, "photoshopPicker");

     if (error) goto returnError;

     error = sPSActionControl->Play(&result, eventSet, desc0000000000000700, plugInDialogSilent);

     if (error) goto returnError;

returnError:

     if (result != NULL) sPSActionDescriptor->Free(result);

     if (desc0000000000000700 != NULL) sPSActionDescriptor->Free(desc0000000000000700);

     if (ref00000000000002a0 != NULL) sPSActionReference->Free(ref00000000000002a0);

     if (desc0000000000000708 != NULL) sPSActionDescriptor->Free(desc0000000000000708);

     return error;

}

HugoTW
HugoTWAuthor
Participating Frequently
November 2, 2017

Hello Tom,

Thanks for your reply!

I do use ColorMunger as a sample to play around.

There is a runtime error occurred in this function.

void AcquireSuite(bool throwError = true);

From

sPSActionDescriptor->Make(&desc0000000000000700);

Do you have any idea what is going wrong?

Thanks

Tom Ruark
Tom RuarkCorrect answer
Inspiring
November 3, 2017

You need to be an automation plug-in for my code to work.

For a filter you can read the fore/back colors from the FilterRecord here: these are read only

FilterColor backColor; /**< The current background color, in the

                                     color space native to the image.*/

FilterColor foreColor; /**< The current foreground color, in the

                                     color space native to the image.*/