public void trimRect(final Rectangle aRect)
    {
        int lastX = aRect.x;
        int lastY = aRect.y;
        int firstX = aRect.x + aRect.width;
        int firstY = aRect.y + aRect.height;
        boolean bFoundAPixel = false;
        
        for (int y=aRect.y; y<aRect.y + aRect.height; ++y)
        {
            for (int x=aRect.x; x<aRect.x + aRect.width; ++x)
            {
                if (!isTransparentAt(x, y))
                {
                    bFoundAPixel = true;
                    
                    if (x < firstX)
                        firstX = x;
                    if (y < firstY)
                        firstY = y;
                    if (x+1 > lastX)
                        lastX = x+1;
                    if (y+1 > lastY)
                        lastY = y+1;
                }
            }
        }

        if (bFoundAPixel)
        {
            aRect.x = firstX;
            aRect.y = firstY;
            aRect.width = lastX - firstX;
            aRect.height = lastY - firstY;
        }
        else
        {
            aRect.width = 0;
            aRect.height = 0;
        }           
    }