Closed AurL closed 7 years ago
It's actually due to an update for Unity 5.5(.0f3) where textureFormat is replaced by textureCompression. To fix:
private void getBytesFromTexture(ref Texture2D texture, out byte[] pixels, IMAGETYPE imageFormat)
{
//Make texture readable
TextureImporter im = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;
bool readable = im.isReadable;
TextureImporterCompression format = im.textureCompression;
TextureImporterType type = im.textureType;
if (!readable)
im.isReadable = true;
if (type != TextureImporterType.Default)
im.textureType = TextureImporterType.Default;
im.textureCompression = TextureImporterCompression.Uncompressed;
im.SaveAndReimport();
if (imageFormat == IMAGETYPE.RGBA)
pixels = texture.EncodeToPNG();
else
pixels = texture.EncodeToJPG(imageFormat == IMAGETYPE.NORMAL_MAP ? jpgQualityNormalMap : jpgQuality);
if (!readable)
im.isReadable = false;
if (type != TextureImporterType.Default)
im.textureType = type;
im.textureCompression = format;
im.SaveAndReimport();
}
Fixed in 1.0.0. Closing
Issue with a PSD texture, it seems that the format is not correctly saves here