コード例 #1
0
 /// <summary>
 /// Adds a new <see cref="IImageFormat"/> to the collection of supported image formats.
 /// </summary>
 /// <param name="format">The new format to add.</param>
 public void AddImageFormat(IImageFormat format)
 {
     if (this.imageFormats.All(i => i.GetType() != format.GetType()))
     {
         this.imageFormats.Add(format);
     }
 }
コード例 #2
0
        /// <summary>
        /// 将图片转为base64字符串
        /// 使用指定格式,并添加data:image/jpg;base64,前缀
        /// </summary>
        /// <param name="img">图片对象</param>
        /// <param name="imageFormat">指定格式</param>
        /// <returns></returns>
        public static string ToBase64StringUrl(Image img, IImageFormat imageFormat)
        {
            string base64 = ToBase64String(img, imageFormat);

            var type = imageFormat.GetType();

            var formatName = "jpg";

            if (type == typeof(JpegFormat))
            {
            }
            else if (type == typeof(BmpFormat))
            {
                formatName = "bmp";
            }
            else if (type == typeof(PngFormat))
            {
                formatName = "png";
            }
            else if (type == typeof(GifFormat))
            {
                formatName = "gif";
            }

            return($"data:image/{formatName};base64,{base64}");
        }