I have a image with src = "data:image/png;base64...."
.
I want to convert this image into byte array byte[]
.
I have tried something like this:
string[] Base64 = ImageData.Split(new char[] { ',' });
byte[] imageBytes = System.Convert.FromBase64String(Base64[1].ToString());
What am I doing wrong here?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.
After language 'B', Dennis Ritchie came up with another language which was based upon 'B'. As in alphabets B is followed by C and hence he called this language as 'C'.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
C# 8 version, without using Regex
or MemoryStream
:
var base64Image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAJFBMVEUAAACAgIAAAAD/AACAAAAAAP8AgAAA/wAAAICAgAD//wD///9wmW9uAAAAAXRSTlMAQObYZgAAAAFiS0dECx/XxMAAAAAHdElNRQfiBhoANycSsUctAAAA60lEQVQoz53Qv07DMBAG8DtH2X2JsscfaaFMIe4TFB4gRLLEzNAHYCA7ElLnbGVkw0+JnYSqDVu/LT9d7o+JrgovQf2rWJbUaiGalZx/J1QzJESfhuhaEGLmujKh/GEUyNwi4dzi0e6A+FdKJVvOK2t3e5ipRSm2qewW/XssaVPKSmlu7HY9geaUM+DJNhMoatlFqXDbv5mxRSsuwwHY969mvLVopbtzL8B6HMuKi2esXLc5TnsQgwt8uu7eD2baXZAF+Pjy3zNQPOQA74e/e0nC2I33OAFxoOOPOX+msNtwAVE0XcoSSOi6/ALgpCd992FfggAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxOC0wNi0yNlQwMDo1NTozOS0wNDowMAwZ2oMAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTgtMDYtMjZUMDA6NTU6MzktMDQ6MDB9RGI/AAAAAElFTkSuQmCC";
var offset = base64Image.IndexOf(',') + 1;
var imageInBytes = Convert.FromBase64String(base64Image[offset..^0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With