skip to Main Content

I am capturing a URI in ASP.NET MVC with webcam.js. I would like to turn this URI to to bitmap in C#. Below is my current code for attempting to parse the URI into a bitmap, but it, but it gives error "Invalid length for a Base-64 char array or string" when creating the byte buffer. I’ve also tried pulling it in as a C# Uri type, but haven’t had any luck.

[HttpPost]
public JsonResult Scan(string file)
{
   Bitmap img = null;
   var matchGroups = Regex.Match(file, @"^data:((?<type>[w/]+))?;base64,(?<data>.+)$").Groups;
   var base64Data = matchGroups["data"].Value;
   byte[] byteBuffer = Convert.FromBase64String(base64Data);
   MemoryStream memoryStream = new MemoryStream(byteBuffer);
   memoryStream.Flush();
   memoryStream.Position = 0;
   img = (Bitmap)Bitmap.FromStream(memoryStream);
}

Here is my URI that is posted from the webcam.js object data_uri which renders the image fine in html.

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnVFJDAAABoAAAAChiVFJDAAABoAAAACh3dHB0AAAByAAAABRjcHJ0AAAB3AAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAFgAAAAcAHMAUgBHAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAABvogAAOPUAAAOQWFlaIAAAAAAAAGKZAAC3hQAAGNpYWVogAAAAAAAAJKAAAA EAAC2z3BhcmEAAAAAAAQAAAACZmYAAPKnAAANWQA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jxxxhZIDU3gYlIEHnlIY/aBHzykI/9rG7OUoJCaAc12eFl0EhNEtBwsmIiDKKAyIcJEnKSwxvpk PdJK0uSgeXOg2NwGepQa DIlbFpolnbvYWUWg/ISST7Ej1a1lR9Nv8sH9EmaVayD6QEeySS0RK5NynaUqYO1sKWnQZt/KEkkW7AdToMknaE8gAn6R ySSFwMyANogR9lIQCDhJJSxMxEPCw d/KSSkTHP hpIP7pN5CSSaDoyTgpRLZSSTYPgaBkrEkmEklIzLclPAkJJIExU E2oIJyUkkDYm5apC0RKSSaKQwE5TvA 6SSlkjoWHOJdCSSYmKU4NxKSSQ0YHKa8wkkgfQgZErPJSSTQIzJmJSHlJJAzCwcpJIZMR0flTyNjoHBSSTRSMBoLktx3R4SSSAeMhO3kOhJJKRRgfUcpJJKI5Q6P/2Q==

Thank you for any help!

2

Answers


  1. Your regular expression is incorrect.

    The base-64 data starts after base64, in the data URI. Note the comma. Your regular expression includes the comma in the data capture group. You need to put it outside the capture group:

    @"^data:((?<type>[w/]+))?;base64,(<data>.+)$"
    
    Login or Signup to reply.
  2. [HttpPost]
            public JsonResult Scan(string file)
            {
                byte[] data = Convert.FromBase64String(file.Substring(file.LastIndexOf(',') + 1));
                Image image;
                Bitmap bitmap;
                using (MemoryStream ms = new MemoryStream(data))
                {
                    image = Image.FromStream(ms);
                    bitmap = new Bitmap(image);
                }
            }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search