How to invert or negate the colors in an image using Salesforce Apex

Color inversion can be a striking stylistic choice, however, this procedure can be difficult to pull off when using Apex. If you would rather skip a whole heap of suffering, then I have a nice shortcut that I can show you now.

We will be using an API to get our negation done quickly. We start by downloading its client files:

Location the client folder and copy it right into your project in Apex. Once that’s done, you will be able to use the library and call this function right here:

SwagEditApi api = new SwagEditApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'imageFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersBlob result = api.editInvert(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

And boom! You’re done! How easy was that!

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.