I need to calculate a close crop rectangle for a bitmap by a given background color key. In the following pictures you can see what is meant to be the close crop. On the left side is the source, on the right side output of the close crop:


As you can see, I need to find the topmost, leftmost, lowermost and rightmost pixels which differ in color from the background to build the close crop rectangle. So, how to find those differing outer pixels to get the close crop rectangle ? Or, in other words, how to calculate close crop rectangle of a bitmap ?
You can use this code (you may follow the
commented versionof this post as well):