イメージングの概要

ここでは、Microsoft Windows Presentation Foundation Imaging Componentの概要を説明します。 WPF Imagingを使用すると、イメージの表示、変換、および書式設定を行うことができます。

このトピックは、次のセクションで構成されています。

  • WPF イメージング コンポーネント
  • WPF イメージ形式
  • WPF でのイメージの表示
  • イメージ メタデータ
  • コーデック拡張機能
  • 関連トピック

WPF イメージング コンポーネント

WPF Imagingでは、Microsoft Windows 内のイメージング機能が大幅に強化されています。 ビットマップの表示や一般的なコントロール上でのイメージの使用などのイメージング機能は、以前は Microsoft Windows Graphics Device Interface (GDI) または Microsoft Windows GDI+ ライブラリに依存していました。 これらの API では、基本的なイメージング機能は提供されていますが、コーデック拡張機能のサポートや忠実性の高いイメージのサポートなどの機能は含まれていません。 WPF Imagingは、GDI および GDI+ の欠点を克服し、アプリケーション内でイメージを表示および使用するための新しい API のセットを提供するために設計されています。

WPF Imagingの API、マネージ コンポーネント、およびアンマネージ コンポーネントにアクセスするには、2 つの方法があります。 アンマネージ コンポーネントは、次の機能を提供します。

  • 新しいイメージ形式または専用のイメージ形式の拡張モデル。

  • bitmap (BMP)、Joint Photographics Experts Group (JPEG)、Portable Network Graphics (PNG)、Tagged Image File Format (TIFF)、Microsoft Windows Media Photo、Graphics Interchange Format (GIF)、アイコン (.ico) などのネイティブ イメージ形式に対するパフォーマンスとセキュリティの向上。

  • 1 チャネルあたり 8 ビット (1 ピクセルあたり 32 ビット) までの高いビット深度のイメージ データの保存。

  • 非破壊のイメージ スケーリング、トリミング、および回転。

  • 簡略化された色の管理。

  • ファイル内の専用のメタデータのサポート。

  • マネージ コンポーネントでは、アンマネージ インフラストラクチャを利用して、user interface (UI)、アニメーション、グラフィックスなどのその他の WPF の機能とイメージとのシームレスな統合を提供します。 マネージ コンポーネントには、WPF アプリケーション内の新しいイメージ形式の自動認識を可能にする、Windows Presentation Foundation (WPF) のイメージング コーデック拡張モデルによる利点もあります。

WPF Imagingのマネージ API の大部分は System.Windows.Media.Imaging 名前空間にありますが、ImageBrushImageDrawing などのいくつかの重要な種類は System.Windows.Media 名前空間にあり、ImageSystem.Windows.Controls 名前空間にあります。

ここでは、マネージ コンポーネントに関する追加情報を提供します。 アンマネージ API の詳細については、「Unmanaged WPF Imaging Component」を参照してください。

WPF イメージ形式

コーデックは特定のメディア形式をデコードまたはエンコードするために使用されます。 WPF Imaging には、BMP、JPEG、PNG、TIFF、Windows Media Photo、GIF、および ICON のイメージ形式のコーデックが含まれます。 これらのコーデックにより、アプリケーションでは、それぞれのイメージ形式のデコードと、ICON を除く各イメージ形式のエンコードを実行できるようになります。

BitmapSource はイメージのデコードとエンコードに使用される重要なクラスです。 これは WPF Imaging パイプラインの基本的なビルド ブロックであり、単一の一定なピクセル セットを特定のサイズおよび解像度で表します。 BitmapSource は複数のフレーム イメージの個別のフレームとしたり、BitmapSource で実行される変換の結果にしたりできます。 これは BitmapFrame などの WPF イメージングで使用される主なクラスの多くの親です。

BitmapFrame は、イメージ形式の実際のビットマップ データを格納するために使用されます。 GIF や TIFF などの形式は 1 イメージあたり複数のフレームをサポートしますが、多くのイメージ形式は単一の BitmapFrame のみをサポートします。 フレームは、デコーダーによって入力データとして使用され、イメージ ファイルを作成するためにエンコーダーに渡されます。

BitmapFrame がどのように BitmapSource から作成され、TIFF イメージに追加されるかを次の例に示します。

Dim image5 As BitmapSource = System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96, PixelFormats.Indexed1, BitmapPalettes.WebPalette, pixels, stride)

Dim stream5 As New FileStream("palette.tif", FileMode.Create)
Dim encoder5 As New TiffBitmapEncoder()
encoder5.Frames.Add(BitmapFrame.Create(image5))
encoder5.Save(stream5)
BitmapSource image5 = BitmapSource.Create(
    width,
    height,
    96,
    96,
    PixelFormats.Indexed1,
    BitmapPalettes.WebPalette,
    pixels,
    stride);

FileStream stream5 = new FileStream("palette.tif", FileMode.Create);
TiffBitmapEncoder encoder5 = new TiffBitmapEncoder();
encoder5.Frames.Add(BitmapFrame.Create(image5));
encoder5.Save(stream5);

イメージ形式のデコード

イメージ デコードとは、イメージ形式をシステムで使用できるイメージ データに変換することです。 その後、イメージ データは、表示、処理、または別の形式にエンコードするために使用できます。 デコーダーは、イメージ形式に基づいて選択されます。 特定のデコーダーが指定されない限り、コーデックの選択は自動的に行われます。 「WPF でのイメージの表示」セクションで、自動デコードの例を示します。 WPF Imagingの アンマネージ インターフェイスを使用して開発され、システムに登録されたカスタム形式デコーダーは、自動的にデコーダーの選択に追加されます。 これによって、カスタム形式を自動的に WPF アプリケーションで表示できるようになります。

ビットマップ デコータを使用して BMP 形式のイメージをデコードする例を次に示します。

' Open a Uri and decode a BMP image
Dim myUri As New Uri("tulipfarm.bmp", UriKind.RelativeOrAbsolute)
Dim decoder2 As New BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim bitmapSource2 As BitmapSource = decoder2.Frames(0)

' Draw the Image
Dim myImage2 As New Image()
myImage2.Source = bitmapSource2
myImage2.Stretch = Stretch.None
myImage2.Margin = New Thickness(20)

// Open a Uri and decode a BMP image
Uri myUri = new Uri("tulipfarm.bmp", UriKind.RelativeOrAbsolute);
BmpBitmapDecoder decoder2 = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource2 = decoder2.Frames[0];

// Draw the Image
Image myImage2 = new Image();
myImage2.Source = bitmapSource2;
myImage2.Stretch = Stretch.None;
myImage2.Margin = new Thickness(20);

// Open a Uri and decode a BMP image
System::Uri^ myUri = gcnew System::Uri("tulipfarm.bmp", UriKind::RelativeOrAbsolute);
BmpBitmapDecoder^ decoder2 = gcnew BmpBitmapDecoder(myUri, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapSource^ bitmapSource2 = decoder2->Frames[0];

// Draw the Image
Image^ myImage2 = gcnew Image();
myImage2->Source = bitmapSource2;
myImage2->Stretch = Stretch::None;
myImage2->Margin = System::Windows::Thickness(20);

イメージ形式のエンコード

イメージ エンコードとは、イメージ データを特定のイメージ形式に変換することです。 その後、エンコードされたイメージ データは、新しいイメージ ファイルを作成するために使用できます。 WPF Imagingは、前に説明したイメージ形式のそれぞれに対するエンコーダーを提供します。

エンコーダーを使用して新しく作成されるビットマップ イメージを保存する例を次に示します。

Dim stream As New FileStream("new.bmp", FileMode.Create)
Dim encoder As New BmpBitmapEncoder()
Dim myTextBlock As New TextBlock()
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString()
encoder.Frames.Add(BitmapFrame.Create(image))
encoder.Save(stream)
FileStream stream = new FileStream("new.bmp", FileMode.Create);
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
encoder.Frames.Add(BitmapFrame.Create(image));
encoder.Save(stream);
FileStream^ stream = gcnew FileStream("new.bmp", FileMode::Create);
BmpBitmapEncoder^ encoder = gcnew BmpBitmapEncoder();
TextBlock^ myTextBlock = gcnew TextBlock();
myTextBlock->Text = "Codec Author is: " + encoder->CodecInfo->Author->ToString();
encoder->Frames->Add(BitmapFrame::Create(image));
encoder->Save(stream);

WPF でのイメージの表示

Windows Presentation Foundation (WPF) アプリケーションでイメージを表示するにはいくつかの方法があります。 イメージは、Image コントロールを使用して表示したり、ImageBrush を使用してビジュアル上に描画したり、ImageDrawing を使用して描画したりできます。

イメージ コントロールの使用

Image は、フレームワーク要素であり、アプリケーション内のイメージを表示する主な方法です。 XAML では、Image を属性構文とプロパティ構文の 2 つの方法で使用できます。 属性構文とプロパティ タグ構文の両方を使用して、幅が 200 ピクセルのイメージをレンダリングする方法を次の例に示します。 属性およびプロパティの構文については、「依存関係プロパティの概要」を参照してください。

<!-- Simple image rendering. However, rendering an image this way may not
     result in the best use of application memory. See markup below which
     creates the same end result but using less memory. -->
<Image Width="200" 
Source="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg"/>

<Image Width="200">
  <Image.Source>
    <!-- To save significant application memory, set the DecodePixelWidth or  
     DecodePixelHeight of the BitmapImage value of the image source to the desired 
     height and width of the rendered image. If you don't do this, the application will 
     cache the image as though it were rendered as its normal size rather then just 
     the size that is displayed. -->
    <!-- Note: In order to preserve aspect ratio, only set either DecodePixelWidth
         or DecodePixelHeight but not both. -->
    <BitmapImage DecodePixelWidth="200"  
     UriSource="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg" />
  </Image.Source>
</Image>

多くの例で、イメージ ファイルの参照に BitmapImage オブジェクトを使用しています。 BitmapImage は、Extensible Application Markup Language (XAML) 読み込み用に最適化された専用の BitmapSource で、イメージを Image コントロールの Source として簡単に表示できる方法です。

コードを使用して幅が 200 ピクセルのイメージをレンダリングする方法を次の例に示します。

メモメモ

BitmapImage は、複数のプロパティでの初期化を最適化するために ISupportInitialize インターフェイスを実装しています。プロパティを変更できるのは、オブジェクトの初期化時だけです。BeginInit を呼び出して初期化が開始されたことを通知し、EndInit を呼び出して初期化が完了したことを通知します。初期化されると、プロパティの変更は無視されます。

' Create Image Element
Dim myImage As New Image()
myImage.Width = 200

' Create source
Dim myBitmapImage As New BitmapImage()

' BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit()
myBitmapImage.UriSource = New Uri("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg")

' To save significant application memory, set the DecodePixelWidth or  
' DecodePixelHeight of the BitmapImage value of the image source to the desired 
' height or width of the rendered image. If you don't do this, the application will 
' cache the image as though it were rendered as its normal size rather then just 
' the size that is displayed.
' Note: In order to preserve aspect ratio, set DecodePixelWidth
' or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 200
myBitmapImage.EndInit()
'set image source
myImage.Source = myBitmapImage
// Create Image Element
Image myImage = new Image();
myImage.Width = 200;

// Create source
BitmapImage myBitmapImage = new BitmapImage();

// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg");

// To save significant application memory, set the DecodePixelWidth or  
// DecodePixelHeight of the BitmapImage value of the image source to the desired 
// height or width of the rendered image. If you don't do this, the application will 
// cache the image as though it were rendered as its normal size rather then just 
// the size that is displayed.
// Note: In order to preserve aspect ratio, set DecodePixelWidth
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
//set image source
myImage.Source = myBitmapImage;

イメージの回転、変換、およびトリミング

WPF を使用すると、ユーザーは、BitmapImage のプロパティを使用して、または CroppedBitmapFormatConvertedBitmap などの追加 BitmapSource オブジェクトを使用して、イメージを変換できます。 これらのイメージの変換では、イメージのスケーリングまたは回転、イメージのピクセル形式の変更、またはイメージのトリミングを行うことができます。

イメージの回転は、BitmapImageRotation プロパティを使用して実行されます。 回転は、90°単位でのみ可能です。 次の例では、イメージが 90°回転されます。

<Image Width="150" Margin="5" Grid.Column="0" Grid.Row="1">
  <Image.Source>
    <TransformedBitmap Source="/sampleImages/watermelon.jpg" >
      <TransformedBitmap.Transform>
        <RotateTransform Angle="90"/>
      </TransformedBitmap.Transform>
    </TransformedBitmap>
  </Image.Source>
</Image>
' Create Image element.
Dim rotated90 As New Image()
rotated90.Width = 150

' Create the TransformedBitmap to use as the Image source.
Dim tb As New TransformedBitmap()

' Create the source to use as the tb source.
Dim bi As New BitmapImage()
bi.BeginInit()
bi.UriSource = New Uri("sampleImages/watermelon.jpg", UriKind.RelativeOrAbsolute)
bi.EndInit()

' Properties must be set between BeginInit and EndInit calls.
tb.BeginInit()
tb.Source = bi
' Set image rotation.
Dim transform As New RotateTransform(90)
tb.Transform = transform
tb.EndInit()
' Set the Image source.
rotated90.Source = tb
// Create Image element.
Image rotated90 = new Image();
rotated90.Width = 150;

// Create the TransformedBitmap to use as the Image source.
TransformedBitmap tb = new TransformedBitmap();

// Create the source to use as the tb source.
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"sampleImages/watermelon.jpg", UriKind.RelativeOrAbsolute);
bi.EndInit();

// Properties must be set between BeginInit and EndInit calls.
tb.BeginInit();
tb.Source = bi;
// Set image rotation.
RotateTransform transform = new RotateTransform(90);
tb.Transform = transform;
tb.EndInit();
// Set the Image source.
rotated90.Source = tb;

グレースケールなどの別のピクセル形式へのイメージの変換は、FormatConvertedBitmap を使用して行われます。 次の例では、イメージが Gray4 に変換されます。

<!-- Grayscale XAML Image -->
<Image Width="200" Grid.Column="0" Grid.Row="1">
   <Image.Source>
      <FormatConvertedBitmap Source="/sampleImages/rocks.jpg"  DestinationFormat="Gray4" />
   </Image.Source>
</Image>
'Create Image Element
Dim grayImage As New Image()
grayImage.Width = 200
grayImage.Margin = New Thickness(5)

'Create source using xaml defined resource.
Dim fcb As New FormatConvertedBitmap(CType(Me.Resources("masterImage"), BitmapImage), PixelFormats.Gray4, Nothing, 0)
'set image source
grayImage.Source = fcb
//Create Image Element
Image grayImage = new Image();
grayImage.Width = 200;
grayImage.Margin = new Thickness(5);

//Create source using xaml defined resource.
FormatConvertedBitmap fcb = new FormatConvertedBitmap(
   (BitmapImage)this.Resources["masterImage"],PixelFormats.Gray4,null,0);
//set image source
grayImage.Source = fcb;

イメージをトリミングするには、Image または CroppedBitmapClip プロパティを使用できます。 通常、イメージの一部を表示するだけの場合は、Clip を使用する必要があります。 トリミングされたイメージをエンコードして保存する必要がある場合は、CroppedBitmap を使用する必要があります。 次の例では、イメージが EllipseGeometry を使用している Clip プロパティを使用してトリミングされます。

<!-- Cropping an Image using Clip -->
<Image Width="200" Grid.Column="0" Grid.Row="5" Margin="5"
   Source="/sampleImages/gecko.jpg">
  <Image.Clip>
    <EllipseGeometry Center="75,50" RadiusX="50" RadiusY="25" />
  </Image.Clip>
</Image>
' Create the image for clipping
Dim clipImage As New Image()
clipImage.Width = 200
clipImage.Margin = New Thickness(5)

'Create & Set source
Dim bi As New BitmapImage()
' BitmapImage properties must be in a BeginInit/EndInit block
bi.BeginInit()
bi.UriSource = New Uri("pack://application:,,/sampleImages/gecko.jpg")
bi.EndInit()
clipImage.Source = bi

' Clip the using an EllipseGeometry
Dim clipGeometry As New EllipseGeometry(New System.Windows.Point(75, 50), 50, 25)
clipImage.Clip = clipGeometry
//Create the image for clipping
Image clipImage = new Image();
clipImage.Width = 200;
clipImage.Margin = new Thickness(5);

//Create & Set source
BitmapImage bi = new BitmapImage();
//BitmapImage.UriSource must be in a BeginInit/EndInit block
bi.BeginInit();
bi.UriSource = new Uri("pack://application:,,/sampleImages/gecko.jpg");
bi.EndInit();
clipImage.Source = bi;

//Clip the using an EllipseGeometry
EllipseGeometry clipGeometry = new EllipseGeometry(new Point(75, 50), 50, 25);
clipImage.Clip = clipGeometry;

イメージの引き伸ばし

Stretch プロパティは、コンテナーを塗りつぶすためにイメージを引き伸ばす方法を制御します。 Stretch プロパティは、Stretch 列挙体によって定義された次の値を受け入れます。

  • None : イメージは出力領域を塗りつぶすために引き伸ばされません。 イメージが出力領域よりも大きい場合は、そのイメージは出力領域に描画され、領域に収まらない部分がトリミングされます。

  • Fill : イメージは出力領域に合わせてスケーリングされます。 イメージの高さと幅は別々にスケーリングされるため、イメージの元の縦横比が維持されない場合があります。 つまり、出力コンテナーを完全に塗りつぶすために、イメージがいびつになることがあります。

  • Uniform : イメージは、出力領域内に完全に収まるようにスケーリングされます。 イメージの縦横比は維持されます。

  • UniformToFill : イメージは、イメージの元の縦横比を維持しながら、出力領域を完全に塗りつぶすようにスケーリングされます。

利用可能な各 Stretch 列挙体を Image に適用する例を次に示します。

次のイメージはこの例の出力結果を表示したものであり、異なる Stretch 設定をイメージに適用した場合の効果を示しています。

さまざまな Stretch 設定

別の TileBrush Stretch 設定

<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" >
  <DockPanel>

    <Border DockPanel.Dock="Top" Background="Black">
      <TextBlock Foreground="White" HorizontalAlignment="Stretch" FontSize="20">
        Stretching an Image
      </TextBlock>
    </Border>

    <Grid Name="simpleGrid" Background="{StaticResource CheckeredBrushResource}" 
       Margin="10" 
       ShowGridLines="True"
       VerticalAlignment="Center"
       HorizontalAlignment="Center">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="175" />
        <ColumnDefinition Width="175" />
        <ColumnDefinition Width="175" />
        <ColumnDefinition Width="175" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="200"/>
      </Grid.RowDefinitions>
      <!-- Labels -->
      <TextBlock Style="{StaticResource Header1}" 
        Grid.Column="0" Grid.Row="0">None</TextBlock>
      <TextBlock Style="{StaticResource Header1}" 
        Grid.Column="1" Grid.Row="0">Uniform</TextBlock>
      <TextBlock Style="{StaticResource Header1}" 
        Grid.Column="2" Grid.Row="0">UniformToFill</TextBlock>
      <TextBlock Style="{StaticResource Header1}"
        Grid.Column="3" Grid.Row="0">Fill</TextBlock>
      <Border Grid.Column="0" Grid.Row="1" BorderThickness="1" BorderBrush="Black">
        <!-- None: Image is not scaled. If image is larger than the
             output area, the image will be cropped to the size of the output area.-->
        <Image
          Source="sampleImages/gecko.jpg" 
          Stretch="None" />
      </Border>
      <Border Grid.Column="1" Grid.Row="1" BorderThickness="1" BorderBrush="Black">
        <!-- Uniform: Scale to fit output area.
             Aspect ratio is preserved.-->
        <Image
          Source="sampleImages/gecko.jpg" 
          Stretch="Uniform" />
      </Border>
      <Border Grid.Column="2" Grid.Row="1" BorderThickness="1" BorderBrush="Black">
        <!-- UniformToFill: Scale to completely fill output area.
             Aspect ratio is preserved. Cropping may occur.-->
        <Image  
          Source="sampleImages/gecko.jpg" 
        Stretch="UniformToFill" />
      </Border>
      <Border Grid.Column="3" Grid.Row="1" BorderThickness="1" BorderBrush="Black">
      <!-- Fill: Scale to completely fill output area.
             Aspect ratio may not be preserved.-->
      <Image 
        Source="sampleImages/gecko.jpg" 
        Stretch="Fill" />
      </Border>
    </Grid>
  </DockPanel>
</Page>

イメージによる塗りつぶし

イメージは、Brush を使用して塗りつぶすことによってもアプリケーション内に表示できます。 ブラシを使用すると、UI オブジェクトに、純色やパターンとイメージの複雑なセットなどを適用できます。 イメージで塗りつぶすには、ImageBrush を使用します。 ImageBrush は、ビットマップ イメージとしてコンテンツを定義する TileBrush の一種です。 ImageBrush を使用した場合、その ImageSource プロパティで指定した単一のイメージが表示されます。 イメージをどのように伸縮、配置、および並べて表示するかを制御できるため、ゆがみを防ぎ、パターンやその他の効果を適用できます。 ImageBrush で適用できるいくつかの効果を次の図に示します。

イメージ ブラシは、図形、コントロール、テキストなどの塗りつぶしを行うことができます。

ImageBrush の出力例

ImageBrush を使用してイメージによってボタンの背景を塗りつぶす方法を次の例に示します。

<!-- Sets the button's Background property with an ImageBrush. The resulting
     button has an image as its background. -->
<Button Grid.Row="3" Grid.Column="2" 
 Height="75" Width="100" Foreground="White" FontWeight="Bold"
 HorizontalAlignment="Left">
  A Button
  <Button.Background>
    <ImageBrush ImageSource="sampleImages\blueberries.jpg" />
  </Button.Background>
</Button>

ImageBrush とイメージの描画の詳細については、「イメージ、描画、およびビジュアルによる塗りつぶし」を参照してください。

イメージ メタデータ

一部のイメージ ファイルには、コンテンツまたはファイルの特性を表すメタデータが含まれています。 たとえば、ほとんどのデジタル カメラでは、イメージをキャプチャするために使用されたカメラの型とモデルに関するメタデータを含むイメージが作成されます。 各イメージ形式ではそれぞれ異なる方法でメタデータを処理しますが、WPF Imagingでは、各サポート対象のイメージ形式のメタデータを保存および取得するための統一された方法が提供されます。

メタデータへのアクセスは BitmapSource オブジェクトの Metadata プロパティによって提供されます。 Metadata は、イメージに含まれるすべてのメタデータを格納する BitmapMetadata オブジェクトを返します。 このデータは、1 つのメタデータ スキーマまたはさまざまなスキーマの組み合わせにすることができます。 WPF Imagingは、Exchangeable image file (Exif)、tEXt (PNG Textual Data)、image file directory (IFD)、International Press Telecommunications Council (IPTC)、Extensible Metadata Platform (XMP) などのイメージ メタデータ スキーマをサポートします。

メタデータの読み取りのプロセスを簡略化するために、BitmapMetadata は、AuthorTitleCameraModel などの簡単にアクセスできるいくつかの名前付きプロパティを提供します。 これらの名前付きプロパティの多くはメタデータを書き込むためにも使用できます。 メタデータ クエリ リーダーによって、メタデータを読み取るための追加サポートが行われます。 GetQuery メソッドは、"/app1/exif/" などの文字列クエリを提供することによって、メタデータ クエリ リーダーを取得するために使用されます。 次の例では、GetQuery"/Text/Description" の場所に格納されているテキストを取得するために使用されます。

' Add the metadata of the bitmap image to the text block.
Dim myTextBlock As New TextBlock()
myTextBlock.Text = "The Description metadata of this image is: " + pngInplace.GetQuery("/Text/Description").ToString()

// Add the metadata of the bitmap image to the text block.
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "The Description metadata of this image is: " + pngInplace.GetQuery("/Text/Description").ToString();

// Add the metadata of the bitmap image to the text block.
TextBlock^ myTextBlock = gcnew TextBlock();
myTextBlock->Text = "The Description metadata of this image is: " + pngInplace->GetQuery("/Text/Description")->ToString();

メタデータを書き込むには、メタデータ クエリ ライターが使用されます。 SetQuery はクエリ ライターを取得し、必要な値を設定します。 次の例では、SetQuery"/Text/Description" の場所に格納されているテキストを書き込むために使用されます。

Dim pngStream As New System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim pngDecoder As New PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim pngFrame As BitmapFrame = pngDecoder.Frames(0)
Dim pngInplace As InPlaceBitmapMetadataWriter = pngFrame.CreateInPlaceBitmapMetadataWriter()
If pngInplace.TrySave() = True Then
    pngInplace.SetQuery("/Text/Description", "Have a nice day.")
End If
pngStream.Close()
Stream pngStream = new System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
PngBitmapDecoder pngDecoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame pngFrame = pngDecoder.Frames[0];
InPlaceBitmapMetadataWriter pngInplace = pngFrame.CreateInPlaceBitmapMetadataWriter();
if (pngInplace.TrySave() == true)
{ pngInplace.SetQuery("/Text/Description", "Have a nice day."); }
pngStream.Close();
Stream^ pngStream = gcnew FileStream("smiley.png", FileMode::Open, FileAccess::ReadWrite, FileShare::ReadWrite);
PngBitmapDecoder^ pngDecoder = gcnew PngBitmapDecoder(pngStream, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapFrame^ pngFrame = pngDecoder->Frames[0];
InPlaceBitmapMetadataWriter^ pngInplace = pngFrame->CreateInPlaceBitmapMetadataWriter();
if (pngInplace->TrySave() == true)
{
   pngInplace->SetQuery("/Text/Description", "Have a nice day.");
}
pngStream->Close();

コーデック拡張機能

WPF Imagingのコア機能は、新しいイメージ コーデックの拡張モデルです。 これらのアンマネージ インターフェイスを使用すると、コーデック開発者は、WPF アプリケーションで新しいイメージ形式を自動的に使用できるように、コーデックを WPF に統合できます。

拡張 API のサンプルについては、Win32 サンプル コーデックを参照してください。 このサンプルでは、カスタム イメージ形式のデコーダーおよびエンコーダーを作成する方法を示します。

メモメモ

コーデックには、システムで認識するために、デジタル署名を行う必要があります。

参照

参照

BitmapSource

BitmapImage

Image

BitmapMetadata

概念

パフォーマンスの最適化 : 2D グラフィックスとイメージング

その他の技術情報

Win32 サンプル コーデック