using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Mail_ImageItem : MonoBehaviour { public RawImage mainImage; public RectTransform rectTransform; public void SetImageData( string imageData) { Debug.Log(imageData); UILogManager.Instance.text1.text = imageData; imageData = imageData.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+"); if (imageData.Length % 4 > 0) { imageData = imageData.PadRight(imageData.Length + 4 - imageData.Length % 4, '='); } Texture2D pic = new Texture2D(190, 190, TextureFormat.RGBA32, false); byte[] data = System.Convert.FromBase64String(imageData.Trim('\0')); pic.LoadImage(data); Adaption(pic); mainImage.texture = pic; } public void Adaption(Texture tex) { float standard_width = 150f; float standard_height = 84f; float video_width = tex.width; float video_height = tex.height; //Debug.Log(tex.width + "***" + tex.height); if (standard_width < video_width && standard_height > video_height) { float video_aspect = standard_width / video_width; rectTransform.sizeDelta = new Vector2(standard_width, video_height * video_aspect); } else if (standard_width > video_width && standard_height < video_height) { float video_aspect = standard_height / video_height; rectTransform.sizeDelta = new Vector2(video_width * video_aspect, standard_height); } else if (standard_width > video_width && standard_height > video_height) { if (standard_width / video_width > standard_height / video_height) { float video_aspect = standard_height / video_height; rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect); } else { float video_aspect = standard_width / video_width; rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect); } } else { if (standard_width / video_width > standard_height / video_height) { float video_aspect = standard_height / video_height; rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect); } else { float video_aspect = standard_width / video_width; rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect); } } } }