- Home /
The sprite size is still the original size after resize the texture in OnPostprocessTexture
Hi guys,
In my project, I need to resize a sprite texture after it is imported. So I did this in AssetPostprocessor.OnPostprocessTexture(). But I noticed that the texture size was changed but the sprite size in Sprite Editor was still the original size. Like below screen shot shown: 
I simplified my code as below to reproduce this problem easier. In the code, it will horizontally duplicate the original texture which means the width of imported texture is supposed to be twice as the original texture. It is in asset Inspector. But it isn't in Sprite Editor.
using System.IO;
using UnityEditor;
using UnityEngine;
public class CustomImporter : AssetPostprocessor
{
void OnPostprocessTexture(Texture2D texture)
{
TextureImporter importer = assetImporter as TextureImporter;
importer.textureType = TextureImporterType.Sprite;
Color[] pixels = texture.GetPixels();
int width = texture.width;
int height = texture.height;
texture.Resize(width * 2, height);
texture.SetPixels(0, 0, width, height, pixels);
texture.SetPixels(width, 0, width, height, pixels);
}
}
Any body encountered same problem before? Any idea is welcome!
Thanks,
Cheng
Your answer
Follow this Question
Related Questions
Can I rearrange slices sliced by the Sprite Editor? 0 Answers
URGENT!!! Not able to slice in the sprite editor 2 Answers
how do I fix the error messege "trying to read pixel out of bounds unityeditor.DockArea:OnGui () 1 Answer
Visual in sprite editor - then invisible sprites in scene + gui??? -- images included 0 Answers
unity package manager completely gray 0 Answers