Unity中(图片裁剪)从一张大图中截取指定位置和大小的小图
原文链接:https://blog.csdn.net/li1214661543/article/details/105437955?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-105437955-blog-
·
/// <summary>
/// 从一张大图中截取指定位置和大小的小图
/// </summary>
/// <param name="m_texPlayer">大图</param>
/// <param name="cur_x">开始截取的x位置</param>
/// <param name="cur_y">开始截取的y位置</param>
/// <param name="width">截取的宽度</param>
/// <param name="height">截取的高度</param>
/// <returns>返回截取后的小图</returns>
public Texture2D DePackTexture(Texture2D m_texPlayer, int cur_x, int cur_y, int width,int height)
{
Texture2D newTexture=new Texture2D(width, height);
for (int m = cur_y; m < height + cur_y; m++)
{
for (int n = cur_x; n < width + cur_x; n++)
{
newTexture.SetPixel(n - cur_x, m - cur_y, m_texPlayer.GetPixel(n, m));
}
}
newTexture.Apply();
return newTexture;
}
更多推荐
已为社区贡献1条内容
所有评论(0)