When does the Bitmap property of a PreviewView become available?

Nathan Sokalski 4,111 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?

Developer technologies | .NET | Xamarin
Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | 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.
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,161 Reputation points Microsoft External Staff
    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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.