I’m creating a dynamic IAB panel that all IAB data come form server, image data receive as byte array that is png file and I set it into the Image UI but the problem is my image cropped in the Image control. The code I’m using is:
public Image buyItemImage;
// the RectTrasform of Image control
public RectTransform buyItemImageRectTrasform;
Sprite sprite = getImageAsset((int)buyItemImageRectTrasform.rect.width, (int)buyItemImageRectTrasform.rect.height);
buyItemImage.sprite = sprite;
public Sprite getImageAsset(int width, int height)
{
Texture2D texture2D = new Texture2D(width, height);
texture2D.LoadImage(imageAsset);
Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f));
return sprite;
}