In the original code, the dictionary transparentPixelsByCoord used a Point as a key. For whatever reason, this causes a significant overhead whenever transparentPixelsByCoord.Add is called. With a large image that has many transparent pixels, the function can take tens of seconds to process. I changed the key type for this dictionary to uint, and created two functions to convert a Point into a uint and back. The x coordinate is stored in the upper region of the int and the y coordinate in the lower. The only limitation with this is that an image can not be bigger than 65535x65535, though I would imagine that in most instances such large images would not be used. However, if bigger resolutions are needed, a ulong can be used instead of an int.
In the original code, the dictionary transparentPixelsByCoord used a Point as a key. For whatever reason, this causes a significant overhead whenever transparentPixelsByCoord.Add is called. With a large image that has many transparent pixels, the function can take tens of seconds to process. I changed the key type for this dictionary to uint, and created two functions to convert a Point into a uint and back. The x coordinate is stored in the upper region of the int and the y coordinate in the lower. The only limitation with this is that an image can not be bigger than 65535x65535, though I would imagine that in most instances such large images would not be used. However, if bigger resolutions are needed, a ulong can be used instead of an int.