赞
踩
/// <summary> /// TextureToBase64普通转换 /// </summary> /// <param name="texture2D"></param> /// <returns></returns> public static string TextureToBase64(Texture2D texture2D) { byte[] imageData = texture2D.EncodeToJPG(); string baser64 = Convert.ToBase64String(imageData); return baser64; } /// <summary> /// 图片文件普通转换 /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static string TextureFileBase64(string filePath) { FileStream filestream = new FileStream(filePath, FileMode.Open); byte[] arr = new byte[filestream.Length]; filestream.Read(arr, 0, (int)filestream.Length); string baser64 = Convert.ToBase64String(arr); filestream.Close(); return baser64; } /// <summary> /// TextureToBase64网页解析专用 /// </summary> /// <param name="texture2D"></param> /// <returns></returns> public static string TextureToBase64_Prefixing(Texture2D texture2D) { return "data:image/jpeg;base64," + TextureToBase64(texture2D); }
public static Texture2D Base64ToTexture(string imageData)
{
Texture2D pic = new Texture2D(190, 190, TextureFormat.RGBA32, false);
byte[] data = System.Convert.FromBase64String(imageData);
pic.LoadImage(data);
return pic;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。