I have following base 64 image:
var image='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA0gA...';
I am using Convert.FromBase64String()
to convert this to bytes:
byte[] bytes = Convert.FromBase64String(convert);
But before this, I need to strip out the header of Base 64 string (i.e data:image/png;base64
). I am doing this using:
string convert = image.Replace("data:image/png;base64,", string.Empty);
I can write the same statement for all image extensions separately, but these images are very large and scanning through each one seems inefficient.
I searched this solution which uses regular expression in PHP to cut off the header part, while other answer in PHP uses an inbuilt method get_contents
.
My Question is: Is there any inbuilt method to get only contents of base 64 url in C#? If not, then is there any generalized way to strip out header for all extensions?