0
我想將一個base64字符串變成一個在Unity 3D中的精靈,但是我的場景中的精靈仍然是空白的。加載一個來自websocket的base64字符串的精靈
public var cardPicture : Image;
function ReceiveData(jsonReply : JSONObject) {
var pictureBytes : byte[] = System.Convert.FromBase64String(jsonReply.GetString("picture"));
var cardPictureTexture = new Texture2D(720, 720);
Debug.Log(cardPictureTexture.LoadImage(pictureBytes));
var sprite : Sprite = new Sprite();
sprite = Sprite.Create (cardPictureTexture, new Rect (0,0,720,720), new Vector2 (0.5f, 0.5f));
cardPicture.overrideSprite = sprite;
}
這打印出來是真實的,但我不知道它是否正確地從字節加載圖像或如果別的東西出錯了。我不確定要檢查什麼以確定發生了什麼問題。爲場景中的卡片分配一些圖片正確顯示。
我記錄了jsonReply.picture,並使用在線base64圖像轉換器,它正確顯示圖像。
圖片來自websocket連接:/ – Waltari