-3

We are calculating the opacity using the following formula

float alpha = 1 - transparency ; // transparency is a float value .

Now the user will be supplying transparency in int format ... What changes should I make to get the opacity ?

sameer karjatkar
  • 2,017
  • 4
  • 23
  • 43

1 Answers1

0

You will need to know the range of possible alpha values in the floating point format. Assuming the range of possible floating point alpha values is between 0.0 and 1.0 (inclusive), then this will work:

#include <cmath>

long lalpha{std::lround(alpha * 255)};

In case the upper bound on the floating point alpha range is not equal to 1.0, you can divide the floating point alpha value by the upper bound to normalize to a range from 0.0 to 1.0 inclusive.

Ton van den Heuvel
  • 10,157
  • 6
  • 43
  • 82