不知道你想要什麼你的邊界的樣子,但你可以做一個顏色替換像這樣使用Texture2D.GetData()函數:
private Color TRANSPARENT = Color.Transparent;
private Color BAD_COLOR = Color.Purple;
private const int DEVIATION = 10;
public Texture2D trimImage(Texture2D texture)
{
/// Get the data from the original texture and place it in an array
Color[] colorData = new Color[texture.Width * texture.Height];
texture.GetData<Color>(colorData);
/// Loop through the array and change the RGB values you choose
for (int x = 0; x < texture.Width; x++)
{
for (int y = 0; y < texture.Height; y++)
{
Color pixel = colorData[x * texture.Height + y];
/// Check if the color is within the range
if (MathHelper.Distance(pixel.R, BAD_COLOR.R) < DEVIATION &&
MathHelper.Distance(pixel.G, BAD_COLOR.G) < DEVIATION &&
MathHelper.Distance(pixel.B, BAD_COLOR.B) < DEVIATION &&
pixel.A != 0f)
{
/// Make that color transparent
pixel = TRANSPARENT;
}
}
}
/// Put the color array into the new texture and return it
texture.SetData<Color>(colorData);
return texture;
}
如果能夠做出不同的邊境僅改變環路參數並選擇合適的像素。希望它有幫助
不確定這是你正在嘗試做什麼,但它可能對你有幫助:http://www.jgallant.com/auto-calculating-bounding-box-from-texture-在-monogame-XNA / – jgallant 2014-10-16 14:53:10