Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Device Camera with Blazor

I have a Blazor Web Assembly PWA, how do I open a devices native camera?

I am trying to write a PWA to capture and save pictures.

EDIT

Would like to save captured images as jpeg's to Azure Blob Storage.

like image 969
Anthony Ryan Avatar asked Aug 06 '20 00:08

Anthony Ryan


People also ask

Is Blazor worth using?

The framework enables developers to build interactive and reusable web UI in existing web technologies like C# or HTML. When it comes to grammar and syntax, the framework allows developers to use the ones of Razor and C#. Even though Blazor has accumulated only 9k+ starts on GitHub, it's still worth considering.

Can Blazor access local files?

Blazor code can now browse local file systems and open up local files and edit them in native Windows apps.


2 Answers

You can achieve this with HTML input. You only need to add the attribute capture for opening device camera straight away.

<input type="file" accept="image/*" capture>

You can have a look at the full source code here:

https://github.com/mehmettahameral/Blazor-wasm-pwa-camera

and live demo here: https://infallible-bohr-56743b.netlify.app/

--

about saving the images: it depends where do you want to save it really. If you can tell me more, I might update the solution.

Hope it helps 🤞

like image 127
Mehmet Taha Meral Avatar answered Nov 15 '22 09:11

Mehmet Taha Meral


You can follow this tutorial: https://wellsb.com/csharp/aspnet/blazor-webcam-capture to capture camera device, stream the content, process an image.

Then, you can use the Azure Blob Storage client library v12 for .NET to upload your images to your Storage Account.

You can find a Quickstart here: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet

like image 23
Andres Talavera Avatar answered Nov 15 '22 11:11

Andres Talavera