How to save "Automatic Truecolor" PNG asset?

Hey guys

I have written an editor script that generates a texture and then saves it to a PNG file that is immediately imported as a texture asset.

generatedTexture = GenerateSomething();

// Export as PNG file
string pngAssetPath = "Assets/Test.png";
File.WriteAllBytes(
    Directory.GetCurrentDirectory() + "/" + pngAssetPath,
    generatedTexture.EncodeToPNG()
);
AssetDatabase.ImportAsset(pngAssetPath);

// Assign generated texture asset to material
material.mainTexture = AssetDatabase.LoadAssetAtPath(
	pngAssetPath, typeof(Texture2D)
) as Texture2D;


// But... the generated texture needs to be "Automatic Truecolor"
// in this particular scenario

How can I ensure that the texture defaults to “Automatic Truecolor” instead of “Automatic Compressed”?

Okay, I seem to have found a working solution, though it would be great if somebody could confirm the correctness of this:

string pngAssetPath = "Assets/test.png";
File.WriteAllBytes(
    Directory.GetCurrentDirectory() + "/" + pngAssetPath,
    _atlasTexture.EncodeToPNG()
);
 
// ** Seems wasteful:
AssetDatabase.ImportAsset(pngAssetPath);
 
TextureImporter textureImporter = TextureImporter.GetAtPath(pngAssetPath) as TextureImporter;
textureImporter.textureFormat = TextureImporterFormat.ARGB32;
AssetDatabase.ImportAsset(pngAssetPath);
 
material.mainTexture = AssetDatabase.LoadAssetAtPath(pngAssetPath, typeof(Texture2D)) as Texture2D;