- Home /
The question is answered, right answer was accepted
Resize texture from prefab?
Hello community,
I am trying to obtain icons from prefabs by using AssetPreview.GetAssetPreview. It works, but the default size for the newly generated images is 128x128. code:
rawIcon = AssetPreview.GetAssetPreview(target);
icon = rawIcon as Texture2D;
byte[] bytes = icon.EncodeToPNG();
Is there away to get larger images? I tried resizing the resulting texture after using AssetPreview.GetAssetPreview, but the pictures are blank:
icon.Resize(512,512);
Thank you
Answer by Bunny83 · Jan 23, 2020 at 11:02 AM
As you can read in the Resize documentation it does not resize the content. It just dumps the current conent and essentially creates a new internal texture with the new size.
You can use my TextureTools which provide two different methods to resample a texture. If the target aspect ratio is different from the source aspect ratio, depending on which method you use you either get a cropped texture or a letterboxed texture. When the aspect ration is the same it just resamples the image using bilinear filtering. I've written those TextureTools in response to this question.
It should be obvious that resampling to a whole multiple of the original image would yield the best result. However due to the bilinear filtering you could resample it to any size you like.
Follow this Question
Related Questions
Getting Prefab Icon from AssetDatabase 0 Answers
Populate inventory with item icons 1 Answer
Instantiating RawImage 1 Answer
Get Asset Preview (3.5) 1 Answer
How to get game icon via code? 2 Answers