Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot result does not fit preview #98

Closed
KrizCologne opened this issue Sep 19, 2023 · 5 comments
Closed

Snapshot result does not fit preview #98

KrizCologne opened this issue Sep 19, 2023 · 5 comments

Comments

@KrizCologne
Copy link

The feed shown in the CameraView is different to the resulting Snapshot file or ImageSource:

Screenshot_20230919_072221

As you can see, the result-image shows more from the top and less from the bottom. I'm playing around with aspect property of the image but the problem might be that the camerafeed just showing a cutout.

myView:


<VerticalStackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <cv:CameraView x:Name="cameraView" WidthRequest="300" HeightRequest="300" CamerasLoaded="CameraView_CamerasLoaded" AutoSnapShotFormat="PNG"/>
        <Button Text="Smile" Clicked="Button_Clicked"/>
        <Image x:Name="myIMage" WidthRequest="300" HeightRequest="300" Clip="ToBounds"/>
    </VerticalStackLayout>

Code behind:

    private async void CameraView_CamerasLoaded(object sender, EventArgs e)
    {
        cameraView.Camera = cameraView.Cameras.First();

        if (cameraView.NumCamerasDetected > 0)
        {
     
            MainThread.BeginInvokeOnMainThread(async () =>
            {
                await cameraView.StopCameraAsync();
                await cameraView.StartCameraAsync();
            });
            
        }
    }
    private async void Button_Clicked(object sender, EventArgs e)
    {        
        myIMage.Source = cameraView.GetSnapShot();
    }
@jsgg25
Copy link

jsgg25 commented Nov 2, 2023

I had the same issue, the capture didn't match the preview. While reviewing the plugin code, I found something that, in my case, fixed the error
image

In this line, a 0 was being passed for the x and y positions, which represent the starting point of the bitmap. However, if the preview does not match the maximum screen camera size, that offset must be considered.

bitmap = Bitmap.CreateBitmap(bitmap, (bitmap.Width - Width)/2, (bitmap.Height - Height) / 2, Width, Height);

@KrizCologne
Copy link
Author

Great, that did the job! @jsgg25 Thank you!

@aleksandervalle
Copy link

This does indeed fix the issue but this change is not done in the repo, and so the issue should still be open.

@janusw
Copy link

janusw commented Feb 22, 2024

FYI: This is fixed in release 1.4.7, built from my fork.

@yassirtl
Copy link

How

I had the same issue, the capture didn't match the preview. While reviewing the plugin code, I found something that, in my case, fixed the error image

In this line, a 0 was being passed for the x and y positions, which represent the starting point of the bitmap. However, if the preview does not match the maximum screen camera size, that offset must be considered.

bitmap = Bitmap.CreateBitmap(bitmap, (bitmap.Width - Width)/2, (bitmap.Height - Height) / 2, Width, Height);

How could i use this bitmap function to solve the problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants