public static bool WriteImageTGA(this Texture2D source, string filename)
        {
            if (source == null)
            {
                UnityEngine.Debug.LogException(new Exception("No source image to save to disk: " + filename));
                return(false);
            }
            bool       result = false;
            FileStream file   = new FileStream(filename, FileMode.Create, FileAccess.Write);

            try {
                byte[] bytes = source.EncodeToTGA();
                if (bytes != null)
                {
                    MemoryStream buffer = new MemoryStream(bytes);
                    buffer.Position = 0;
                    buffer.CopyTo(file, CopyToOptions.FlushFinal);
                    buffer.Close();
                    buffer.Dispose();
                    buffer = null;
                    bytes  = null;
                    result = File.Exists(filename);
                    if (result == false)
                    {
                        throw new Exception("Failed to save texture file to disk: " + filename);
                    }
                }
                else
                {
                    throw new Exception("Failed to encode texture image to disk: " + filename);
                }
            } catch (Exception ex) {
                UnityEngine.Debug.LogException(ex);
            } finally {
                file.Close();
            }
            return(result);
        }