When does the Bitmap property of a PreviewView become available?

Nathan Sokalski 4,126 Reputation points
2023-04-04T04:58:13.2433333+00:00

I have an AndroidX.Camera.View.PreviewView from which I want to continuously/periodically look at the value of the Bitmap property. However, immediately after starting the preview, the Bitmap property is null, so trying to look at the Bitmap property is not possible, and I am not sure how to detect when it becomes available. If possible, I do not want to stop displaying preview when looking at the Bitmap property. How can I detect when the Bitmap property becomes available?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,647 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 39,391 Reputation points Microsoft Vendor
    2023-04-05T02:12:09.4+00:00

    Hello,

    After further investigation, you could detect to Bitmap's values using delegates and non-blocking threads, please refer to the following code example:

    public delegate void DelegateWithParameters(PreviewView p);
    
    // implement the delegate method
    private void DetectBitMap(PreviewView p)
    {
        while (true)
        {
            if (p.Bitmap != null)
            {
                ...
            }
        }
    }
    
    // invoke this method
    DelegateWithParameters delFoo =
    new DelegateWithParameters(DetectBitMap);
    delFoo.BeginInvoke(viewFinder, null, null);
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments