I have an application where I need to resize the users picture to max. 50KB
To resize I use a Method that sizes the picture to a given Width/Height.
The picture is a Bitmap with max. 8BPP. (Width * Height * 8) = Size in Bits
What I need to know now is: How can I calculate the amount of pixels I need to cut off to reach a maximum size of 50 KB. The result should be as close to the maximum as possible. (Not just cut off more than enough).
There's a tolerance of some Kilo Bytes but not too much.
Let $r$ be the ratio of width/height of the original picture - you want to preserve that. Now you just have to solve $$ y \cdot(1+r) = 50 \cdot 1024 \cdot 8. $$ Then $\underline{y}$ is the height of the resized picture in pixels and, where $\underline{y}$ is the maximal integer less than or equal to $y$ and setting $x := y \cdot r$, $\underline{x}$ is the height of the resized picture.