Udostępnij za pośrednictwem


WalletBarcode.GetImageAsync Method

Definition

Caution

The ApplicationModel.Wallet namespace is no longer supported, and will soon be deprecated. Developers are encouraged to avoid using this namespace.

Creates and returns a bitmap image stream for the barcode (or returns the custom image used during instantiation).

public:
 virtual IAsyncOperation<IRandomAccessStreamReference ^> ^ GetImageAsync() = GetImageAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<IRandomAccessStreamReference> GetImageAsync();
/// [Windows.Foundation.Metadata.RemoteAsync]
/// [Windows.Foundation.Metadata.Deprecated("IWalletBarcode is deprecated and might not work on all platforms. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 917504, "Windows.Foundation.UniversalApiContract")]
IAsyncOperation<IRandomAccessStreamReference> GetImageAsync();
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<IRandomAccessStreamReference> GetImageAsync();
[Windows.Foundation.Metadata.RemoteAsync]
[Windows.Foundation.Metadata.Deprecated("IWalletBarcode is deprecated and might not work on all platforms. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 917504, "Windows.Foundation.UniversalApiContract")]
public IAsyncOperation<IRandomAccessStreamReference> GetImageAsync();
function getImageAsync()
Public Function GetImageAsync () As IAsyncOperation(Of IRandomAccessStreamReference)

Returns

An asynchronous operation. If you use Asynchronous programming, the result type on successful completion is an IRandomAccessStreamReference instance. This can be assigned as the source for an image (with some additional code).

Attributes

Remarks

If the WalletBarcode object was instantiated using the WalletBarcode constructor that takes a custom image as a parameter, that custom image is returned on completion. Otherwise, an image of the system-defined barcode is created and then returned.

This method doesn't literally return an image object that's ready for UI, it returns a stream that defines a bitmap image. To actually set an image, you can use code similar to this:

<Button Content="Generate barcode" Click="Button_Click"/>
<Image x:Name="barcodeImage"/>
private async void Button_Click(object sender, RoutedEventArgs e)
{
    var walletBarcode = new WalletBarcode(WalletBarcodeSymbology.Qr, "123123123123");

    IRandomAccessStreamReference streamRef = await walletBarcode.GetImageAsync();
    IRandomAccessStream stream = await streamRef.OpenReadAsync();

    var bitmapImage = new BitmapImage();
    await bitmapImage.SetSourceAsync(stream);
    barcodeImage.Source = bitmapImage;
}

Applies to

See also