Giter Site home page Giter Site logo

"Access Error" about camera.maui HOT 5 CLOSED

JasonYangNWI avatar JasonYangNWI commented on August 12, 2024
"Access Error"

from camera.maui.

Comments (5)

hjam40 avatar hjam40 commented on August 12, 2024

Hi! Thank you for your feedback.
This error could be for different reasons... Maybe you has not set the Camera property before call StartCameraAsync? You can try to set MirroredImage property to True before call StartCameraAsync, in android thats changes the PreviewView implementation mode to compatible and maybe it works better in Samsung devices...
Another reason could be an exception when the plugging tries to open the camera, you could clone this git repository and run in debug mode the test program included in your device

from camera.maui.

JasonYangNWI avatar JasonYangNWI commented on August 12, 2024

Hi Hector,
Thanks for the quick reply.
I found the reason. That's because I use ZXing.net.maui to process the barcode on the page before I use Camera.maui.
Apparently, ZXing.net.maui doesn't stop the barcodereaderview automatically, and I didn't find any function to stop it.
Do you have the experience on ZXing.net.maui? Do you know how to stop the barcodereaderview?

After I successfully open the camera, I am going to take a snapshot and save it to a variable.
And then I am going to show it on the image control of next page.
To do that, I call "GetSnapShot". As it returns "ImageSource", I must convert it to Base64 string.
Here is the code.
var imageSource = cameraView.GetSnapShot(ImageFormat.PNG);
var imageSourceStream = await ((StreamImageSource)imageSource).Stream(CancellationToken.None);
using var memoryStream = new MemoryStream();
imageSourceStream.CopyTo(memoryStream);
weighRecord.Picture = Convert.ToBase64String(memoryStream.ToArray());

On the next page, I convert Base64 string back to image source.
var imageBytes = Convert.FromBase64String(weighRecord.Picture);
using MemoryStream memoryStream = new(imageBytes);
contaminationPicture.Source = ImageSource.FromStream(() => memoryStream);

Unfortunately, it doesn't work. Do you know how to show the snapshot in the image control?
Thank you very much.

from camera.maui.

hjam40 avatar hjam40 commented on August 12, 2024

Hi Jason
I know ZXing.net.maui, but this plugging has ZXing.Net integrated too and maybe you don't need the first. You can detect barcodes with the CameraView using the event "BarcodeDetected" and setting the property "BarCodeDetectionEnabled" to True (if you set it to False, the barcode detection stops) and "BarCodeOptions" property.
For image manipulation I recomend you to use the method "SaveSnapShot", It saves the image to a file and then you can read the bytes from the file and convert it to Base64 (wihtout ImageSource).
If you wanna use your code, I think that you have to set the MemoryStream Position to 0 before use it in the ImageSource:
var imageBytes = Convert.FromBase64String(weighRecord.Picture);
using MemoryStream memoryStream = new(imageBytes);
memoryStream.Position = 0;
contaminationPicture.Source = ImageSource.FromStream(() => memoryStream);

from camera.maui.

JasonYangNWI avatar JasonYangNWI commented on August 12, 2024

Hi Hector,

I fixed the image issue. It’s caused by “using” statement.

I am going to replace ZXing.net.maui with your Camera.maui plugin.
Some suggestions to Camera.maui plugin. Is it possible to make it compatible to MVVM pattern? Instead of calling function directly from the control, could you make some bindable property or event, which can be converted to command easily?

Thanks for the help once again.
You can close the issue now.

Jason

from camera.maui.

hjam40 avatar hjam40 commented on August 12, 2024

Hi Jason,

Your suggestion is welcomed. I added bindable properties for the snapshotting and barcode detection.

from camera.maui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.