CSharpImageLibrary.ImageFormats.GetExtensionOfFormat C# (CSharp) Method

GetExtensionOfFormat() public static method

Gets file extension of supported surface formats. Doesn't include preceding dot.
public static GetExtensionOfFormat ( ImageEngineFormat format ) : string
format ImageEngineFormat Format to get file extension for.
return string
        public static string GetExtensionOfFormat(ImageEngineFormat format)
        {
            string formatString = format.ToString().ToLowerInvariant();
            if (formatString.Contains('_'))
                formatString = "dds";

            return formatString;
        }

Usage Example

Example #1
0
        internal string GetAutoSavePath(ImageEngineFormat newformat)
        {
            string newpath        = null;
            bool   acceptablePath = false;
            int    count          = 1;


            string formatString = ImageFormats.GetExtensionOfFormat(newformat);

            string basepath = Path.GetDirectoryName(ImagePath) + "\\" + Path.GetFileNameWithoutExtension(ImagePath) + "." +
                              (newformat == ImageEngineFormat.Unknown ? Path.GetExtension(ImagePath) : formatString);

            newpath = basepath;

            // KFreon: Check that path is not already taken
            while (!acceptablePath)
            {
                if (File.Exists(newpath))
                {
                    newpath = Path.Combine(Path.GetDirectoryName(basepath), Path.GetFileNameWithoutExtension(basepath) + "_" + count++ + Path.GetExtension(basepath));
                }
                else
                {
                    acceptablePath = true;
                }
            }

            return(newpath);
        }