/// <summary>
/// 图片逆时针旋转90度
/// </summary>
/// <param name="src">原图片二进制数据</param>
/// <param name="srcW">原图片宽度</param>
/// <param name="srcH">原图片高度</param>
/// <param name="desTexture">输出目标图片</param>
public static void RotationLeft90(Color32[] src, int srcW, int srcH, Texture2D desTexture)
{
if (pixelsLen != src.Length || des == null)
{
pixelsLen = src.Length;
des = new Color32[pixelsLen];
}
if (desTexture.width != srcH || desTexture.height != srcW)
{
desTexture.Resize(srcH, srcW);
}
for (int i = 0; i < srcW; i++)
{
for (int j = 0; j < srcH; j++)
{
des[i * srcH + j] = src[(srcH - 1 - j) * srcW + i];
}
}
desTexture.SetPixels32(des);
desTexture.Apply();
}
/// <summary>
/// 图片顺时针旋转90度
/// </summary>
/// <param name="src">原图片二进制数据</param>
/// <param name="srcW">原图片宽度</param>
/// <param name="srcH">原图片高度</param>
/// <param name="desTexture">输出目标图片</param>
public static void RotationRight90(Color32[] src, int srcW, int srcH, Texture2D desTexture)
{
if (pixelsLen != src.Length || des == null)
{
pixelsLen = src.Length;
des = new Color32[pixelsLen];
}
if (desTexture.width != srcH || desTexture.height != srcW)
{
desTexture.Resize(srcH, srcW);
}
for (int i = 0; i < srcH; i++)
{
for (int j = 0; j < srcW; j++)
{
des[(srcW - j - 1) * srcH + i] = src[i * srcW + j];
}
}
desTexture.SetPixels32(des);
desTexture.Apply();
}
/// <summary>
/// 图片旋转180度
/// </summary>
/// <param name="src">原图片二进制数据</param>
/// <param name="srcW">原图片宽度</param>
/// <param name="srcH">原图片高度</param>
/// <param name="desTexture">输出目标图片</param>
public static void Rotation180(Color32[] src, int srcW, int srcH, Texture2D desTexture)
{
if (pixelsLen != src.Length || des == null)
{
pixelsLen = src.Length;
des = new Color32[pixelsLen];
}
if (desTexture.width != srcW || desTexture.height != srcH)
{
desTexture.Resize(srcW, srcH);
}
for (int i = 0; i < srcH; i++)
{
for (int j = 0; j < srcW; j++)
{
des[i * srcW + j] = src[(srcH - i) * srcW - j - 1];
}
}
desTexture.SetPixels32(des);
desTexture.Apply();
}
/// <summary>
/// 图片镜像
/// </summary>
/// <param name="src">原图片二进制数据</param>
/// <param name="srcW">原图片宽度</param>
/// <param name="srcH">原图片高度</param>
/// <param name="desTexture">输出目标图片</param>
public static void Mirror(Color32[] src, int srcW, int srcH, Texture2D desTexture)
{
if (pixelsLen != src.Length || des == null)
{
pixelsLen = src.Length;
des = new Color32[pixelsLen];
}
if (desTexture.width != srcW || desTexture.height != srcH)
{
desTexture.Resize(srcW, srcH);
}
for (int i = 0; i < srcH; i++)
{
for (int j = 0; j < srcW; j++)
{
des[i * srcW + j] = src[(i + 1) * srcW - j - 1];
}
}
desTexture.SetPixels32(des);
desTexture.Apply();
}
/// <summary>
/// 图片拷贝
/// </summary>
/// <param name="src">原图片二进制数据</param>
/// <param name="srcW">原图片宽度</param>
/// <param name="srcH">原图片高度</param>
/// <param name="desTexture">输出目标图片</param>
public static void Copy(Color32[] src, int srcW, int srcH, Texture2D desTexture)
{
if (desTexture.width != srcW || desTexture.height != srcH)
{
desTexture.Resize(srcW, srcH);
}
desTexture.SetPixels32(src);
desTexture.Apply();
}