Get ImageFormat from File Extension

后端 未结 4 1978
萌比男神i
萌比男神i 2020-12-25 11:45

Is there quick way to get the ImageFormat object associated to a particular file extension? I\'m looking for quicker than string comparisons for each format.

4条回答
  •  执念已碎
    2020-12-25 12:25

        private static ImageFormat GetImageFormat(string format)
        {
            ImageFormat imageFormat = null;
    
            try
            {
                var imageFormatConverter = new ImageFormatConverter();
                imageFormat = (ImageFormat)imageFormatConverter.ConvertFromString(format);
            }
            catch (Exception)
            {
    
                throw;
            }
    
            return imageFormat;
        }
    

提交回复
热议问题