Problem solved here's the code:
Bitmap b = new Bitmap(filename);
Rectangle r = new Rectangle();
int topLeft = b.Width, topRight = 0, topUpper = b.Height, topBottom = 0;
string whitePixel = "ffffffff";
for (int y = 1; y < b.Height; y++)
{
for (int x = 1; x < b.Width; x++)
{
if (b.GetPixel(x, y).Name != whitePixel)
{
if (x < topLeft)
topLeft = x;
if (x > topRight)
topRight = x;
if (y < topUpper)
topUpper = y;
if (y > topBottom)
topBottom = y;
}
}
}
r.Location = new Point(topLeft-1, topUpper-1);
r.Size = new Size((topRight - topLeft)+1, (topBottom - topUpper)+1);
Bitmap b2 = b.Clone(r, b.PixelFormat);
b2.Save(newfilename, ImageFormat.Gif);