本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:Unity – Color32[]转为byte[]字节数组
原文链接:https://www.stubbornhuang.com/937/
发布于:2020年10月15日 9:56:12
修改于:2020年10月31日 16:42:22

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;
}
参考链接
当前分类随机文章推荐
- Unity - Color32[]转IntPtr 阅读1724次,点赞0次
- Unity - Color32[]转为byte[]字节数组 阅读1976次,点赞1次
- Unity - 字节数组byte[]保存为文件 阅读2464次,点赞2次
全站随机文章推荐
- 资源分享 - GPU Pro 5 - Advanced Rendering Techniques 英文高清PDF下载 阅读1938次,点赞0次
- 资源分享 - Color Imaging - Fundamentals and Applications 英文高清PDF下载 阅读502次,点赞0次
- WordPress - 在erphpdown插件中增加在隐藏文章指定位置之后文章内容的付费查看功能 阅读91次,点赞0次
- C++ - 使用ffmpeg读取视频旋转角度并使用OpenCV根据旋转角度对视频进行旋转复原 阅读540次,点赞0次
- C++ – Unicode编码下的全角字符转半角字符 阅读659次,点赞0次
- Mediapipe - 将Mediapipe handtracking封装成动态链接库dll/so,实现在桌面应用中嵌入手势识别功能 阅读4046次,点赞11次
- C++11 - std::chrono - 使用std::chrono::duration_cast进行时间转换,hours/minutes/seconds/milliseconds/microseconds相互转换,以及自定义duration进行转换 阅读1217次,点赞0次
- 资源分享 - 解读基金:我的投资观与实践(季凯帆,康峰著)PDF下载 阅读990次,点赞0次
- 资源分享 - C++Primer Plus,第6版,中文版,带书签超清 PDF下载 阅读1098次,点赞0次
- WordPress - get_header函数,加载主题头部header模板 阅读170次,点赞0次
评论
144