0
votes

I have a gallery scene and I want to load PNG's from Persistence path .

The thing is that I want them as thumbnails, theirs no need for me to load the full size file .

How can I defined the scale of the sprite? that the relevant line for the creating of the sprite:

  Sprite sp1 = Sprite.Create(texture1, new Rect(0, 0, texture1.width, texture1.height), new Vector2(0.5f, 0.5f), 100, 0, SpriteMeshType.FullRect);

and that the texture creating code:

 Texture2D takeScreenShotImage(string filePath)
{
    Texture2D texture = null;
    byte[] fileBytes;
    if (File.Exists(filePath))
    {
        fileBytes = File.ReadAllBytes(filePath);
        texture = new Texture2D(1, 1, TextureFormat.ETC2_RGB, false);

        texture.LoadImage(fileBytes);
    }
    return texture;
}
1

1 Answers

0
votes

The proper place to make that change is on the Texture2D after loading the Texture. If you really want to load them as thumbnails and want the size to be smaller to save memory then resize it with the Texture2D.Resize function after loading the Texture. The height and width of 60 should be fine. You can then create Sprite from it with Sprite.Create.

Texture2D takeScreenShotImage(string filePath)
{
    Texture2D texture = null;
    byte[] fileBytes;
    if (File.Exists(filePath))
    {
        fileBytes = File.ReadAllBytes(filePath);
        texture = new Texture2D(1, 1, TextureFormat.ETC2_RGB, false);

        texture.LoadImage(fileBytes);
    }

    //RE-SIZE THE Texture2D
    texture.Resize(60, 60);
    texture.Apply();

    return texture;
}

Note that TextureFormat.ETC2_RGB is compressed. To resize it you may have to create a copy of it. See #1 solution from my other post on how to do this.