Assets/Watson/Scripts/Utilities/Utility.cs
/// <summary>
/// Converts Color32 array to Byte array.
/// </summary>
/// <param name="colors">Color32 array of the image.</param>
/// <returns></returns>
Converts Color32 array to Byte array.
Converts Color32 array to Byte array .
public static byte[] Color32ArrayToByteArray(Color32[] colors)
        {
            if (colors == null || colors.Length == 0)
                return null;
            int lengthOfColor32 = Marshal.SizeOf(typeof(Color32));
            int length = lengthOfColor32 * colors.Length;
            byte[] bytes = new byte[length];
            GCHandle handle = default(GCHandle);
            try
            {
                handle = GCHandle.Alloc(colors, GCHandleType.Pinned);
                IntPtr ptr = handle.AddrOfPinnedObject();
                Marshal.Copy(ptr, bytes, 0, length);
            }
            finally
            {
                if (handle != default(GCHandle))
                    handle.Free();
            }
            return bytes;
        }
public static byte [ ] Color32ArrayToByteArray ( Color32 [ ] colors ) { if ( colors == null || colors . Length == 0 ) return null ; int lengthOfColor32 = Marshal . SizeOf ( typeof ( Color32 ) ) ; int length = lengthOfColor32 * colors . Length ; byte [ ] bytes = new byte [ length ] ; GCHandle handle = default ( GCHandle ) ; try { handle = GCHandle . Alloc ( colors , GCHandleType . Pinned ) ; IntPtr ptr = handle . AddrOfPinnedObject ( ) ; Marshal . Copy ( ptr , bytes , 0 , length ) ; } finally { if ( handle != default ( GCHandle ) ) handle . Free ( ) ; } return bytes ; }
Converts Color32 array to Byte array.
Converts Color32 array to Byte array .
None
colors
Color32[]
Color32 array of the image.
Color32 array of the image .