zoukankan      html  css  js  c++  java
  • Unity 图片的旋转

    
            /// <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();
            }
    
  • 相关阅读:
    洛谷P4550 收集邮票 期望dp
    Codeforces Round #748 (Div. 3) G. Changing Brackets
    [Codeforces Round #748 (Div. 3)](https://codeforces.com/contest/1593) F. Red-Black Number 记忆化搜索
    [Codeforces Round #748 (Div. 3)](https://codeforces.com/contest/1593) D2 Half of Same
    HDU 3746 Cyclic Nacklace kmp找循环节
    Codeforces Round #747 (Div.2) D. The Number of Imposters
    Nand2tetris 学习笔记
    怎样解题表
    [省选]知识点板块
    List of Problems to be Solved
  • 原文地址:https://www.cnblogs.com/jingxuan2583/p/14148160.html
Copyright © 2011-2022 走看看