Unity – Color32[]转为byte[]字节数组
原创文章,作者:StubbornHuang,如若转载,请注明出处:《Unity – Color32[]转为byte[]字节数组》https://www.stubbornhuang.com/937/
1 Color32[]转为Byte[]字节数组
代码示例:
private 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;
}
参考链接
当前分类随机文章推荐
全站随机文章推荐
- C++ - 字节数组byte与int的相互转换
- Unity - Color32[]转为byte[]字节数组
- C++11 - override关键字简要介绍
- 资源分享 – Fluid Simulation for Computer Graphics, Second Edition英文高清PDF下载
- C++11 - 基于无锁队列的单生产者单消费者模型
- Marching Cube(C++ OpenGl代码)读取医学三维图像*.raw进行三维重建
- Python3爬虫 - 下载反盗链图片的方式
- C++11 - std::bind简要介绍以及可绑定函数的几种形式总结
- 常用的三维图形库以及软件所使用的坐标系以及旋转正方向
- 资源分享 - Computer Graphics Through OpenGL - From Theory to Experiments (Third Edition) 英文高清原版 PDF下载