【发布时间】:2021-05-30 00:11:12
【问题描述】:
我有一个下载图片的脚本 我希望图像的高度和宽度与屏幕匹配
图片 [1]:https://i.stack.imgur.com/0VcAT.png
图像应该在用户的最佳视野中 顺便说一句,这是一个看漫画的应用程序
" 我非常努力地用最好的方式传达这个想法,我希望我成功了^_^"
感谢您的帮助
脚本
public IEnumerator GetImage(string url)
{
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();
Texture2D myTexture = DownloadHandlerTexture.GetContent(www);
//خوارزمية تعديل حجم الصورة
// Give all 100 of the length or width one number
for(int i = 1; i < 40;)
{
if(i*100 > myTexture.width)
{
for(int u = 1; u < 40;)
{
if(u*100 > myTexture.height)
{
WidthX = i;
HeightX = u;
u = 100;
i = 100;
}
u++;
}
}
i++;
}
// After reducing all 100 to one, scale it down to fit the screen
WidthX = WidthX / 3;
HeightX = HeightX / 3;
//Create sprite and set a Width and Height
Rect rec = new Rect(0, 0, myTexture.width, myTexture.height);
OImg.sprite = Sprite.Create(myTexture, rec, Vector2.zero);
OImg.GetComponent<RectTransform>().localScale = new Vector3 (WidthX,HeightX,1);
}
我通过(localScale)改变了图像的大小,我认为这是一个错误
必须为图片修改“矩形变换宽度和高度”
【问题讨论】: