次の方法で共有


BitmapImage.IsAnimatedBitmap プロパティ

定義

イメージがアニメーション化されているかどうかを示す値を取得します。

public:
 property bool IsAnimatedBitmap { bool get(); };
bool IsAnimatedBitmap();
public bool IsAnimatedBitmap { get; }
var boolean = bitmapImage.isAnimatedBitmap;
Public ReadOnly Property IsAnimatedBitmap As Boolean

プロパティ値

Boolean

bool

イメージがアニメーション化されている場合は true。それ以外の場合は false

Windows の要件

デバイス ファミリ
Windows 10 Anniversary Edition (10.0.14393.0 で導入)
API contract
Windows.Foundation.UniversalApiContract (v3.0 で導入)

この例では、アニメーション GIF の使用方法を示します。 ボタンを使用すると、ユーザーはアニメーションを開始または停止できます。 IsAnimatedBitmap プロパティをオンにすると、ボタンが表示されるか非表示になるかが判断されます。

この例では、バージョン アダプティブ コードを使用して、すべてのバージョンのWindows 10で実行できます。 バージョン 1607 より前のバージョンでは、GIF の最初のフレームが表示されますが、アニメーション化されません。

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Image>
        <Image.Source>
            <BitmapImage x:Name="imageSource"
                         UriSource="Assets/example.gif"
                         ImageOpened="imageSource_ImageOpened"/>
        </Image.Source>
    </Image>

    <AppBarButton x:Name="playButton"
              Icon="Play"
              Visibility="Collapsed"
              Click="playButton_Click"/>
</Grid>
// Show the play/stop button if the image is animated.
private void imageSource_ImageOpened(object sender, RoutedEventArgs e)
{
    var bitmapImage = (BitmapImage)sender;
    // At this point you can query whether the image is animated or not.
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Media.Imaging.BitmapImage", "IsAnimatedBitmap") 
        && bitmapImage.IsAnimatedBitmap == true)
    {
        // Enable the play button
        playButton.Visibility = Visibility.Visible;
    }
}

注釈

バージョン 1607 Windows 10以降、XAML Image 要素はアニメーション GIF イメージをサポートしています。 Image Source として BitmapImage を使用すると、BitmapImage API にアクセスして、アニメーション GIF イメージの再生を制御できます。 詳細については、「 BitmapImage クラス解説」の「アニメーション画像」セクションと アニメーション GIF 再生サンプルを参照してください。

互換性に関する注意事項

アプリがバージョン 1607 より前のWindows 10のリリースで実行されている場合は、ApiInformation クラスを使用して、このプロパティの存在をチェックしてから使用する必要があります。 詳細については、「 バージョン アダプティブ コード: 以前のバージョンとの互換性を維持しながら新しい API を使用する」を参照してください。

適用対象