Ejemplo n.º 1
0
        public byte[] GetBytesFromBase64(string base64StringWebFormat, bool validateImageFormat = true)
        {
            string format = string.Empty;

            if (!string.IsNullOrEmpty(base64StringWebFormat))
            {
                if (validateImageFormat)
                {
                    format = GetImageStringFormat(base64StringWebFormat);
                }

                if (validateImageFormat)
                {
                    if (formatIsValid(format))
                    {
                        return(ImageConvert.GetByteFromBase64(GetBase64Only(base64StringWebFormat)));
                    }
                }

                var    base64Only = GetBase64Only(base64StringWebFormat);
                byte[] bytes      = ImageConvert.GetByteFromBase64(base64Only);
                return(bytes);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public string GetBase64FromBytes(byte[] bytes)
        {
            if (bytes == null)
            {
                return(string.Empty);
            }

            var base64          = ImageConvert.GetBase64FromByte(bytes);
            var base64WebFormat = "data:image/jpeg;base64," + base64;

            return(base64WebFormat);
        }
Ejemplo n.º 3
0
        public Image GetImageFromBase64(string base64String, bool validateImageFormat = true)
        {
            string format = string.Empty;

            if (!string.IsNullOrEmpty(base64String))
            {
                if (validateImageFormat)
                {
                    format = GetImageStringFormat(base64String);
                }

                if (validateImageFormat)
                {
                    if (formatIsValid(format))
                    {
                        return(ImageConvert.FromBase64AsImage(base64String));
                    }
                }
                return(ImageConvert.FromBase64AsImage(base64String));
            }
            return(null);
        }