> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XUserGetGamerPictureAsync

> XUserGetGamerPictureAsync

# XUserGetGamerPictureAsync

Recupera de forma assíncrona a imagem de jogador de um usuário específico.

## Sintaxe

```cpp theme={null}
HRESULT XUserGetGamerPictureAsync(  
         XUserHandle user,  
         XUserGamerPictureSize pictureSize,  
         XAsyncBlock* async  
)  
```

### Parâmetros

*user*   \_In\_\
Tipo: XUserHandle

O usuário para o qual recuperar a imagem de jogador.

*pictureSize*   \_In\_\
Tipo: [XUserGamerPictureSize](/pt-BR/reference/system/xuser/enums/xusergamerpicturesize)

O tamanho da imagem de jogador a ser recuperada.

*async*   \_Inout\_\
Tipo: [XAsyncBlock\*](/pt-BR/reference/system/xasync/structs/xasyncblock)

Um [XAsyncBlock](/pt-BR/reference/system/xasync/structs/xasyncblock) para sondar o status da chamada e recuperar os resultados da chamada.

### Valor retornado

Tipo: HRESULT

Código de sucesso ou erro HRESULT.\
Para obter uma lista de códigos de erro, consulte [Códigos de erro](/pt-BR/reference/errorcodes).

## Comentários

O XR "Nome de exibição e imagem de jogador" lista requisitos específicos sobre como os nomes de usuário e as imagens de avatar são exibidos.
Consulte os Requisitos do XBOX para jogos e aplicativos Hub do XBOX One [(Downloads para desenvolvedores do XBOX->Parceiro, publicação e informações de gerenciamento de lançamento->Documentação de parceiros XGD)](https://www.microsoft.com/software-download/devcenter) para obter detalhes.

Para recuperar o resultado de uma chamada para [XUserGetGamerPictureAsync](/pt-BR/reference/system/xuser/functions/xusergetgamerpictureasync), chame
[XUserGetGamerPictureResult](/pt-BR/reference/system/xuser/functions/xusergetgamerpictureresult).

Para recuperar o tamanho do buffer exigido por [XUserGetGamerPictureResult](/pt-BR/reference/system/xuser/functions/xusergetgamerpictureresult) para recuperar
a imagem de jogador retornada por [XUserGetGamerPictureAsync](/pt-BR/reference/system/xuser/functions/xusergetgamerpictureasync), chame
[XUserGetGamerPictureResultSize](/pt-BR/reference/system/xuser/functions/xusergetgamerpictureresultsize).

O formato da imagem de jogador retornada é uma imagem no formato .PNG. O tamanho da imagem pode ser de até 2^32
bytes.

O exemplo a seguir demonstra como carregar uma imagem de jogador.

```cpp theme={null}
HRESULT LoadGamerPicComplete(XAsyncBlock* abResult)
{
    try
    {
        struct CreateTextureContext
        {
            User* This;
            ImTextureID TextureId;
            std::vector<unsigned char> GamerpicBuffer;
        };

        auto context = std::make_unique<CreateTextureContext>();
        context->This = this;
        context->TextureId = IMTEXTUREID_INVALID;

        // Get the buffer size and set up a buffer to contain it
        size_t bufferSize;
        RETURN_IF_FAILED(XUserGetGamerPictureResultSize(abResult, &bufferSize));
        context->GamerpicBuffer.resize(bufferSize);

        size_t bufferUsed;
        RETURN_IF_FAILED(XUserGetGamerPictureResult(
            abResult,
            context->GamerpicBuffer.size(),
            context->GamerpicBuffer.data(),
            &bufferUsed));
        FAIL_FAST_HR_IF(E_UNEXPECTED, bufferSize != bufferUsed);

        // Create some async work to create a dx texture off the UI thread
        // and then set the texture id back on the UI thread
        auto abCreateTexture = std::make_unique<XAsyncBlock>();
        ZeroMemory(abCreateTexture.get(), sizeof(*abCreateTexture));
        abCreateTexture->queue = abResult->queue;
        abCreateTexture->context = context.get();

        // Set the texture id in the completion on the UI thread
        abCreateTexture->callback = [](XAsyncBlock* ab)
        {
            auto context = static_cast<CreateTextureContext*>(ab->context);
            context->This->_textureId = context->TextureId;
            delete context;
            delete ab;
        };

        // Worker will create the texture on a work thread
        auto createTextureWorker = [](XAsyncBlock* ab) -> HRESULT
        {
            auto context = static_cast<CreateTextureContext*>(ab->context);
            auto dimension = GetDimensionFromSize(GamerPicSize);
            RETURN_IF_FAILED(CreateTextureFromPng(context->GamerpicBuffer.data(), context->GamerpicBuffer.size(), &context->TextureId));
            return S_OK;
        };

        // Create the texture on a work thread
        if (SUCCEEDED_LOG(XAsyncRun(abCreateTexture.get(), createTextureWorker)))
        {
            context.release();
            abCreateTexture.release();
        }
    }
    CATCH_RETURN();
    return S_OK;
}

HRESULT LoadGamerPicAsync(XTaskQueueHandle queue, uint32_t cancelTime = 0)
{
    auto asyncBlock = std::make_shared<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = queue;

    struct GamerPicContext
    {
        User* User;
        std::shared_ptr<XAsyncBlock> AsyncBlock;
    };

    auto context = std::make_unique<GamerPicContext>();
    context->User = this;
    context->AsyncBlock = asyncBlock;
    asyncBlock->context = context.get();

    asyncBlock->callback = [](XAsyncBlock* ab)
    {
        std::unique_ptr<GamerPicContext> context(reinterpret_cast<GamerPicContext*>(ab->context));
        LOG_IF_FAILED(context->User->LoadGamerPicComplete(ab));
    };

    if (cancelTime != 0)
    {
        std::thread cancelThread(
            [asyncBlock]()
        {
            std::this_thread::sleep_for(std::chrono::milliseconds(5000));
            XAsyncCancel(asyncBlock.get());
        });

        cancelThread.detach();
    }

    if (SUCCEEDED_LOG(XUserGetGamerPictureAsync(_handle.get(), GamerPicSize, asyncBlock.get())))
    {
        context.release();
    }

    return S_OK;
}
```

## Requisitos

**Cabeçalho:** XUser.h

**Biblioteca:** xgameruntime.lib

**Plataformas com suporte:** Windows, Steam Deck, consoles da família XBOX One e consoles XBOX Series

## Documentação conceitual

* [Metas de design e melhorias da programação assíncrona](/pt-BR/build/core-features/common/async/async-whitepaper)

## Confira também

[XUser](/pt-BR/reference/system/xuser/xuser_members)

[XUserGetGamerPictureResult](/pt-BR/reference/system/xuser/functions/xusergetgamerpictureresult)

[XUserGetGamerPictureResultSize](/pt-BR/reference/system/xuser/functions/xusergetgamerpictureresultsize)


## Related topics

- [XUserGetGamerPictureAsync](/reference/system/xuser/functions/xusergetgamerpictureasync.md)
- [XUserGamerPictureSize](/reference/system/xuser/enums/xusergamerpicturesize.md)
- [XUserGetGamerPictureResultSize](/reference/system/xuser/functions/xusergetgamerpictureresultsize.md)
- [XUserGetGamerPictureResult](/reference/system/xuser/functions/xusergetgamerpictureresult.md)
