Closed minhaj-inspiredsquare closed 1 year ago
Found solution:
public void DownloadImage(string fileUrl, string name)
{
RestClient.Get(new RequestHelper {
Uri = fileUrl,
DownloadHandler = new DownloadHandlerTexture(true),
Method = "GET",
DefaultContentType = true,
EnableDebug = true,
}).Then(res =>
{
Texture2D tex = ((DownloadHandlerTexture) res.Request.downloadHandler).texture;
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(tex.width / 2, tex.height / 2));
if (img != null)
{
img.overrideSprite = sprite;
img.preserveAspect = true;
}
}).Catch(err => {
Debug.Log(err.Message);
Debug.Log("url: " + fileUrl);
});
}
Hi, I'm trying to download an image from the URL but it gives me the "Specified cast is not valid" error. Here is my code please correct me on what I'm doing wrong: