hjam40 / camera.maui Goto Github PK
View Code? Open in Web Editor NEWA CameraView Control for preview, take photos and control the camera options
License: MIT License
A CameraView Control for preview, take photos and control the camera options
License: MIT License
Hi,
When I was trying to assign the cameraView.FlashMode = FlashMode.Enabled;
In iOS its is working fine and capturing photos with flash. But where as in Android, the flashmode is not working.
I tried to enable FlashMode as below.
cameraView.FlashMode = FlashMode.Enabled;
How do I get each frame of the image and request to add a callback function to get the image
Hi
I'm trying to flip (change) cameras on iOS device but it does not work.
The front camera works fine, but when I click the button to switch to back camera, it stop the camera stream.
I also tried start with the back camera, it works, but when I hit the button to switch to front camera it also stops the stream.
Here is the code:
private void CameraView_CamerasLoaded(object sender, EventArgs e)
{
StartCamera(CameraPosition.Front);
}
private async void StartCamera(CameraPosition position)
{
await MainThread.InvokeOnMainThreadAsync(async () =>
{
await cameraView.StopCameraAsync();
cameraView.Camera = null;
cameraView.Camera = cameraView.Cameras.Where(f => f.Position == position).First();
cameraView.MirroredImage = true;
await cameraView.StartCameraAsync();
canvas.InvalidateSurface();
});
}
void CameraView_FlipCamera(System.Object sender, System.EventArgs e)
{
CameraPosition position = cameraView.Camera.Position == CameraPosition.Front ? CameraPosition.Back : CameraPosition.Front;
StartCamera(position);
}
and xaml:
<cv:CameraView x:Name="cameraView"
Grid.RowSpan="4"
CamerasLoaded="CameraView_CamerasLoaded"
/>
<Button
Grid.Row="0"
Grid.Column="2"
Text="{Binding Source={x:Static helpers:MaterialDesignIconFonts.CameraFlip}}"
Style="{StaticResource TreinifyIconLabelStyle}"
Clicked="CameraView_FlipCamera"
/>
Hi, Thanks for the project. It's a good choice before .NET Maui community toolkit add the cameraview.
I tried it on my Samsung tablet, and got "access error" after calling "StartCameraAsync".
What is the reason of "access error"?
After upgrading to 1.4 I am now getting the following with testing the cameraview on my android device. I have removed all my code so that the only think is the reference to the cameraview in the xaml .
Here is the error
{System.NullReferenceException: Object reference not set to an instance of an object.
at Camera.MAUI.Platforms.Android.MauiCameraView.InitDevices()
at Camera.MAUI.Platforms.Android.MauiCameraView..ctor(Context context, CameraView cameraView)
at Camera.MAUI.CameraViewHandler.CreatePlatformView()
at Microsoft.Maui.Handlers.ViewHandler`2[[Camera.MAUI.CameraView, Camera.MAUI, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null],[Camera.MAUI.Platforms.Android.MauiCameraView, Camera.MAUI, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null]].OnCreatePlatformView() in D:\a_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 72
Hello,
Is there a way to make a lower resolution video using cameraView.StartRecordingAsync?
Thanks for a great control!
Daniel
Using CameraView in a modal stack I found that calling Navigation.PopAsync triggers a crash on Windows at random times. The attached repro illustrates this.
From the main window:
Crash info:
Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.dll
An exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Private.CoreLib.dll but was not handled in user code
Error HRESULT E_FAIL has been returned from a call to a COM component.
This is occurring with the current published nuget, version 1.3.5. The attached repro solution was created new from template today with the latest Visual Studio and MAUI app templates.
hi i want to get each frame from camera preview, so i can use it with luxand face detection.
is it possible to get each frame and how?
如果没有的话,多会能帮忙加一下,万分感谢
Hi
We have tried various camera settings, including the zoom factor, which seems to have no effect on the view port on Android (works fine on iOS).
cameraView.ZoomFactor = 2.5f;
We have tested using a Google Pixel 7 Pro using version 1.3.1. Any thoughts?
Hi
I installed folowing the documentation but I get no preview in the CameraView control.
GetSnapShot() return a null ImageSource.
Any idea ?
For now, it seems the only way to get an image using this plugin is by doing something like cameraView.GetSnapShot(Camera.MAUI.ImageFormat.JPEG);
or am I wrong?
The built-in barcode/QR detection uses the FrameReader_FrameArrived
event as seen here on the Windows platform (haven't looked at the other platform implementations). How about making this event public so consumers can subscribe and process the received frames by, for example, ML algorithms, other QR/Barcode libs or whatever one needs?
If it fits your purpose I am more than willing to try to come up with an implementation, although testing on an IOS device would be hard for me as I don't have one.
When I try to set cv:CameraView
's IsVisible="False"
, or WidthRequest
and HeightRequest
to 0
cameraView.TakePhotoAsync();
returnrs null
when trying to run the program on Android, while on Windows it works perfectly fine. Also WidthRequest
and HeightRequest
of cv:CameraView
affects the quality of the result
from cameraView.TakePhotoAsync()
on Android, when again, on Windows it works perfectly fine.
Here are the snippets of code from MainPage.xaml.cs
and MainPage.xaml
var stream = await cameraView.TakePhotoAsync();
if (stream != null)
{
var result = ImageSource.FromStream(() => stream);
displayImage.Source = result;
}
<cv:CameraView
x:Name = "cameraView"
IsVisible="True"
WidthRequest="100"
HeightRequest="20"
/>
<Image
x:Name="displayImage"
Source="dotnet_bot.png"
IsVisible="True"
Aspect="AspectFit"
/>
My devices`
Hi,
How can I have a button to swap between the front and back cameras?
Thanks,
Jassim
There's a slight typo in the README under "Using CameraView":
xmlns:cv="xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
work fine but with front camera , after switch to back camera have no preview .
I use provided test project in GitHub with no change , just start it .
test phone is honor 8A android 9
also this error showed in output when staring back camera [GLConsumer] [SurfaceTexture-0-20313-0] bindTextureImage: error binding external image: 0x502
As Gerald Versluis in his Video stated: it would be interesting if we could get access to the raw camera feed with this library. Then it would be possible to create augmented reality apps with .NET MAUI.
We have exactly the same issue with an app we are working on, so I figured lets see how others have got around it!
I just pull the repo and run it, click smile, and second click fails with log below:
[0:] Microsoft.Maui.StreamImageSourceService: Warning: Unable to load image stream.
Android.Util.AndroidRuntimeException: Only the original thread that created a view hierarchy can touch its views.
at Java.Interop.JniEnvironment.StaticMethods.CallStaticVoidMethod(JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 13250
at Java.Interop.JniPeerMembers.JniStaticMethods.InvokeVoidMethod(String encodedMember, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniStaticMethods.cs:line 97
at Microsoft.Maui.PlatformInterop.LoadImageFromStream(ImageView imageView, Stream inputStream, IImageLoaderCallback callback) in D:\a_work\1\s\src\Core\src\obj\Release
et7.0-android\generated\src\Microsoft.Maui.PlatformInterop.cs:line 443
at Microsoft.Maui.StreamImageSourceService.LoadDrawableAsync(IImageSource imageSource, ImageView imageView, CancellationToken cancellationToken) in D:\a_work\1\s\src\Core\src\ImageSources\StreamImageSourceService\StreamImageSourceService.Android.cs:line 28
--- End of managed Android.Util.AndroidRuntimeException stack trace ---
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:8798)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1606)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at androidx.drawerlayout.widget.DrawerLayout.requestLayout(DrawerLayout.java:1353)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at androidx.recyclerview.widget.RecyclerView.requestLayout(RecyclerView.java:4586)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at androidx.core.widget.NestedScrollView.requestLayout(NestedScrollView.java:2075)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.widget.ImageView.setImageDrawable(ImageView.java:597)
at androidx.appcompat.widget.AppCompatImageView.setImageDrawable(AppCompatImageView.java:112)
at com.microsoft.maui.glide.MauiCustomViewTarget.onResourceCleared(MauiCustomViewTarget.java:30)
at com.bumptech.glide.request.target.CustomViewTarget.onLoadCleared(CustomViewTarget.java:210)
at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:337)
at com.bumptech.glide.request.ErrorRequestCoordinator.clear(ErrorRequestCoordinator.java:48)
at com.bumptech.glide.manager.RequestTracker.clearAndRemove(RequestTracker.java:70)
at com.bumptech.glide.RequestManager.untrack(RequestManager.java:660)
at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:628)
at com.bumptech.glide.RequestManager.clear(RequestManager.java:624)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:811)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:780)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:771)
at com.microsoft.maui.PlatformInterop.prepare(PlatformInterop.java:229)
at com.microsoft.maui.PlatformInterop.loadInto(PlatformInterop.java:234)
at com.microsoft.maui.PlatformInterop.loadImageFromStream(PlatformInterop.java:265)
--- End of managed Android.Util.AndroidRuntimeException stack trace ---
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:8798)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1606)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at androidx.drawerlayout.widget.DrawerLayout.requestLayout(DrawerLayout.java:1353)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at androidx.recyclerview.widget.RecyclerView.requestLayout(RecyclerView.java:4586)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at androidx.core.widget.NestedScrollView.requestLayout(NestedScrollView.java:2075)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.view.View.requestLayout(View.java:25390)
at android.widget.ImageView.setImageDrawable(ImageView.java:597)
at androidx.appcompat.widget.AppCompatImageView.setImageDrawable(AppCompatImageView.java:112)
at com.microsoft.maui.glide.MauiCustomViewTarget.onResourceCleared(MauiCustomViewTarget.java:30)
at com.bumptech.glide.request.target.CustomViewTarget.onLoadCleared(CustomViewTarget.java:210)
at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:337)
at com.bumptech.glide.request.ErrorRequestCoordinator.clear(ErrorRequestCoordinator.java:48)
at com.bumptech.glide.manager.RequestTracker.clearAndRemove(RequestTracker.java:70)
at com.bumptech.glide.RequestManager.untrack(RequestManager.java:660)
at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:628)
at com.bumptech.glide.RequestManager.clear(RequestManager.java:624)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:811)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:780)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:771)
at com.microsoft.maui.PlatformInterop.prepare(PlatformInterop.java:229)
at com.microsoft.maui.PlatformInterop.loadInto(PlatformInterop.java:234)
at com.microsoft.maui.PlatformInterop.loadImageFromStream(PlatformInterop.java:265)
camera not working in ios
Concerning identification with special services or products it would be usefull that it is pssoible to integrate a logo.
I've run into an issue with permissions in Android on both phones I have for testing.
Even with the AndroidManifest.xml updated as per the documentation, the app doesn't prompt for permissions on start.
I have to specifically check if permission has been granted:
status = await Permissions.CheckStatusAsync<Permissions.Camera>();
When this returns as denied, I can then call:
status = await Permissions.RequestAsync<Permissions.Camera>();
Now, that works the first time the app is run, with no permissions granted. However, once I grant the app permission, the camera will not work on subsequent runs. I have to go into settings and revoke the permissions so it can prompt again and the camera will work again.
Any clues as to why this might be happening?
While invoking TakePhotoAsync() function whole app crashes, I have no idea why because code is same as in example, also project was configured same as shown in readme
Code:
private async void ScanButtonOnClicked(object sender, EventArgs e)
{
var stream = await CameraView.TakePhotoAsync();
if (stream == null) return;
var result = ImageSource.FromStream(() => stream);
ImagePreview.Source = result;
}
Error:
System.ArgumentException: Value does not fall within the expected range.
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.Windows.Graphics.Imaging.ISoftwareBitmapStaticsMethods.Convert(IObjectReference _obj, SoftwareBitmap source, BitmapPixelFormat format, BitmapAlphaMode alpha)
at Windows.Graphics.Imaging.SoftwareBitmap.Convert(SoftwareBitmap source, BitmapPixelFormat format, BitmapAlphaMode alpha)
at Camera.MAUI.Platforms.Windows.MauiCameraView.TakePhotoAsync(ImageFormat imageFormat)
at Camera.MAUI.CameraView.TakePhotoAsync(ImageFormat imageFormat)
at Animatron.MainPage.ScanButton_OnClicked(Object sender, EventArgs e)
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()
Thank you very much
Could you please add a library openCV to the library
Hi Hector,
I tried barcode reader function today. It's very good.
Just one issue.
After I turn on BarCodeDetectionEnabled, the engine keeps working.
As I turn off BarCodeDetectionEnabled inside the event handler, usually my code receives multiple barcode detected events.
Is there any way to detect only once?
Thank you very much.
Jason
Using iOS 16.4, camera view loads along with barcode detection. However the camera view will not focus on a barcode in order to detect it. No exceptions thrown as in latest ZXing library.
After calling "StartCameraAsync", I got System.InvalidCastException on v1.3.1.
I have to revert back to v1.3, which is good.
when the device is rotated, the camera image is not rotated.
Using Gerald Versiuis' two recent Camera.View sample projects, as discussed in his matching YouTube videos, I am unable to see a CameraView preview in either when using a Windows 11 Webcam and running VS 2022 Enterprise Preview. (I had to make minor changes to his csprog files as neither contained a properly-formatted ApplicationIdGuid and an assembly neutral language, both required for Windows.) However, in the earlier project for image capture, an image can be captured from that webcam and properly displayed beneath where the preview should appear. In the latter project for barcode scanning, the same webcam does get started (still no preview), but no barcode detection occurs. Same project works as expected on an actual Android device.
The lack of auto focus keeps us from using this. Does the ZXing control have an AutoFocus method? If so, can you expose it in this control so I can call it periodically? If this is not possible, is there another way to force a focus adjustment?
The camera properties doesn't have The Horizontal and Vertical angles:
for android the old Camera object has:
cameraObject.GetParameters().HorizontalViewAngle
cameraObject.GetParameters().VerticalViewAngle
where cameraObject is the Android.Hardware.Camera.
for iOS the field of view needs to be calculated so:
private void ComputeFOVfromCameraFormat()
{
nfloat aspectRatio = previewLayer.Bounds.Size.Width / previewLayer.Bounds.Size.Height;
if (aspectRatio > 1.0) aspectRatio = 1.0f / aspectRatio;
AVCaptureDeviceFormat activeFormat = this._captureDevice.ActiveFormat;
CoreMedia.CMFormatDescription description = activeFormat.FormatDescription;
CoreMedia.CMVideoDimensions dimensions = activeFormat.HighResolutionStillImageDimensions;
nfloat activeFOV = 2.0f * (float)(Math.Atan(Math.Tan((0.5 * activeFormat.VideoFieldOfView).ToRadians()) / this._captureDevice.VideoZoomFactor) / (Math.PI / 180));
nfloat aspectWidth = (nfloat)dimensions.Height / aspectRatio;
nfloat aspectHeight = (nfloat)dimensions.Width * aspectRatio;
if (this.videoGravity == AVLayerVideoGravity.ResizeAspectFill)
{
nfloat aspectFOV;
if (aspectWidth < dimensions.Width)
{
aspectFOV = (nfloat)(2.0 * Math.Atan(aspectWidth / (nfloat)dimensions.Width * Math.Tan((0.5 * activeFOV).ToRadians())) / (Math.PI/180));
}
else if (aspectHeight < dimensions.Height)
{
aspectFOV = activeFOV;
}
else
{
aspectFOV = activeFOV;
}
_fieldOfViewPortrait = aspectFOV;
_fieldOfViewLandscape = (nfloat)(2.0 * Math.Atan(Math.Tan((0.5 * aspectFOV).ToRadians()) * aspectRatio) / (Math.PI/180));
}
else if (this.videoGravity == AVLayerVideoGravity.ResizeAspect)
{
nfloat aspectFOV;
if (aspectHeight > dimensions.Height)
{
// Left and right bars added (in portrait)
//
aspectFOV = activeFOV;
}
else if (aspectWidth > dimensions.Width)
{
// Top and bottom bars added (in portrait)
//
aspectFOV = (nfloat)(2.0 * Math.Atan(aspectWidth / (nfloat)dimensions.Width * Math.Tan((0.5 * activeFOV ).ToRadians())) / (Math.PI/180));
}
else
{
// Matching aspect ratio -- no bars added
//
aspectFOV = activeFOV;
}
_fieldOfViewPortrait = aspectFOV;
_fieldOfViewLandscape = (nfloat)(2.0 * Math.Atan(Math.Tan((0.5 * aspectFOV ).ToRadians()) * aspectRatio) / (Math.PI/180));
}
}
These properties very useful to detect if an object in the space (x, y, z) is within the camera view range.
so if you add these properties will be great.
example on Android 5
Java.Lang.NoSuchMethodError
Message=no non-static method "Landroid/media/AudioManager;.getMicrophones()Ljava/util/List;"
0x12 in Android.Media.AudioManager.get_Microphones at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Media.AudioManager.cs:1537,6
0x177 in Camera.MAUI.Platforms.Android.MauiCameraView.InitDevices C#
Looks like it just needs an API check similar to the following
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { List<MicrophoneInfo> mics = am.getMicrophones(); ... } else { AudioDeviceInfo[] deviceInfo = am.getDevices(AudioManager.GET_DEVICES_INPUTS); ... }
in Android/MauiCameraView.cs : InitDevices() : line 92
several examples online search for:
no non-static method "Landroid/media/AudioManager;.getMicrophones()Ljava/util/List;"
Ive been trying to use you're Camera.MAUI view in my Blazor MAUI project, however I can't seem to get it to work and all the examples here use XAML.
Ive followed the examples best ive can and making adjustments for Blazor. Which includes adding .UseMauiCameraView
to "Mauiprogram.cs", giving the Android device Camera permissions and adding xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
to MainPage.xaml
However, the bit that i get an error on is: cameraView.Camera = cameraView.Cameras.First();
which is part of the function ran when the button is pressed to display the camera.
Where the issue is that cameraView.Cameras
is never set, which is caused by the CameraViewHandler
never being run and since CameraViewHandler
is Protected i'm not able to call it myself.
Would you know how to address this?
I'm using Camera.MAUI 1.4.3 to read QR code in my app, but if I add to my solution the nuget package CommunityToolkit.Maui it suddently stops working. Camera open correctly but it wont detect the QR code anymore. Is this a known compatibilty issue?
Nice project (works fine under windows by following the mini tuto on the github page), but I have a black screen when I launch the app with an Android device (Samsung galaxy s21 Ultra exynos version). Strange thing, when my app switches to thumbnail (by pressing the home button on my phone), for one frame I see the camera stream, before everything goes black again.
EDIT:
A small track to understand the bug; on this line the value of Width and Height is 0
previewView.LayoutParameters = new LayoutParams { Width = Width, Height = Height };
If I enter arbitrary positive values here, I get my control displayed.
I use the cameraView within a ContentPage, which is pushed async on a shell page.
When navigating back to the shell page it says
'Cannot access a closed Stream.'
This is the case when a snapshot has been taken with
I've noticed that the decoding of QR codes appears to run on ThreadPool tasks based on a timer without any consideration for existing tasks. I can sometimes see upwards of 10 threads running simultaneously depending on how I set the frame rate. This leads to a couple of issues for me:
I want to display my webcam on window, and camera on android.
In android that work but in window no why ?
My code:
`public MainPage()
{
InitializeComponent();
foreach (var i in CameraView.Cameras)
{
Console.WriteLine(i.Name);
}
}
private void CameraView_CamerasLoaded(object sender, EventArgs e)
{
if (CameraView.NumCamerasDetected <= 0) return;
if (CameraView.NumMicrophonesDetected > 0) CameraView.Microphone = CameraView.Microphones.First();
CameraView.Camera = CameraView.Cameras.First();
MainThread.BeginInvokeOnMainThread(async () =>
{
await CameraView.StartCameraAsync();
});
}`
my Package.appxmanifest:
<Capabilities> <rescap:Capability Name="runFullTrust" /> <DeviceCapability Name="webcam"/> <DeviceCapability Name="microphone"/> </Capabilities>
public async Task CameraLoadAsync()
{
if (mainView.camera.Cameras.Count > 0)
{
mainView.camera.Camera = mainView.camera.Cameras.First();
if (mainView.camera == null) return;
MainThread.BeginInvokeOnMainThread(async () =>
{
await mainView.camera.StopCameraAsync();
await mainView.camera.StartCameraAsync();
});
}
}
When trying to StartCameraAsync it gives this error: System.NullReferenceException: 'Object reference not set to an instance of an object.'
I checked but nothing is null neither the camera or cameraView
The saved files using the stream returned from CameraView.TakePhotoAsync();
Are limited to 788x1054 on all the cameras listed on my Samsung S22 Ultra. (front and back)
Can we get an image with the full resolution of the selected camera?
Using version 1.3.5
My code:
while (flag)
{
var file = Path.Combine(FileSystem.Current.CacheDirectory, $"file_{DateTime.Now:hhmmss}.mp4");
var result = await cameraView.StartRecordingAsync(file);
await Task.Delay(10000);
result = await cameraView.StopRecordingAsync();
var f = new FileInfo(file);
Console.WriteLine("file length: " + f.Length);
await Task.Delay(200); //if remove the line it will throw exception
}
But every mp4 file loses 1-2 seconds.
Could you improve it?
example:
StartRecordingAsync(TimeSpan span, Action callback)
StartRecordingToDirectoryAsync(string directory, TimeSpan span)
Suggestion:
Resolution ratio allows configuration.
mediaRecorder.SetVideoSize(540, 320)
Forgive me for my poor english.
Thanks
Hi,
Great project and I hope it helps the MAUI Community Toolkit along but you might want to fix a build error I am seeing where the csproj is referencing an image on your machine.
On a device with Android 8 (API Level 26) the app crashes with the method "CamerasLoaded or MicrophonesLoaded" with the error message:
"**Java.Lang.NoSuchMethodError:** 'no non-static method "Landroid/media/AudioManager;.getMicrophones()Ljava/util/List;"'"
The CamerView works on an emulator with Android 13.
Later I saw that there was already a post about this. I then tried to use the code from the README:
private void camerView_CamerasLoaded(object sender, EventArgs e)
{
if (cameraView.NumCamerasDetected > 0)
{
if (cameraView.NumMicrophonesDetected > 0)
cameraView.Microphone = cameraView.Microphones.First();
cameraView.Camera = cameraView.Cameras.First();
MainThread.BeginInvokeOnMainThread(async () =>
{
await cameraView.StopCameraAsync();
var result = await cameraView.StartCameraAsync();
lblCameraResult.Text = "Camera: " + result.ToString();
});
}
}
Then it doesn't crash, but you always get an AccessError as a result. Can this be fixed somehow?
When using the Popups from the Maui community toolkit on iOS, the cameraView takes over all elements, making it impossible to use buttons.
Steps to reproduce:
On android this will work perfectly fine, but when deploying on iOS the button can not be pressed. When the cameraView is removed, the button can be clicked. It is also possible to click on the background to close the popup, which isnt possible when the CameraView is on the popup.
The code for this problem can also be found here (https://github.com/Jensevent/PopUpTest). In this app myPopup.xaml
is my Community toolkit popup.
I am trying to build to an Iphone 7, working from a mac mini with Ventura 13.4. If you need anything more, just ask.
Camera view quality is very bad & blurry therefore barcode detection not working properly. How to increase image qualty or resolution?
I am using the camera view to take pictures, it works well when I set the build to Debug however as soon as I publish the app and change build to Release the app crashes. It's almost as if it no longer detects the cameras. I have tried it with this sample (https://github.com/jfversluis/MauiCameraMauiSample) as well with the same issues, is there something I am doing wrong ?
See screenshots attached.
Hi, thanks for your project! It really help me lot. 😊
Is it possible to capture a full resolution image from camera?
The "SaveSnapShot()" method gives me an image that was way too small on my phone (iPhone 12 Pro, snapshot was 320px x 640px, 512 KB)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.