public Color GetAvgColor(Texture2D tex, Rectangle rect, int mipLevel = 0)
{
Color[] data = new Color[rect.Width * rect.Height];
if (data.Length == 0) return Color.White;
tex.GetData<Color>(mipLevel, rect, data, 0, data.Length);
int r = data.Sum(t => t.R) / data.Length;
int g = data.Sum(t => t.G) / data.Length;
int b = data.Sum(t => t.B) / data.Length;
int a = data.Sum(t => t.A) / data.Length;
return new Color(r, g, b, a);
}
edit with a bit of explanation: the 3rd overload of the GetData allows you to specify a rectangle to retrieve colours from, so you simply have to make sure your data array is the same size as what your after returning.