DrawingContext クラス
定義
描画、プッシュ、およびポップ コマンドを使用してビジュアル コンテンツを記述します。Describes visual content using draw, push, and pop commands.
public ref class DrawingContext abstract : System::Windows::Threading::DispatcherObject, IDisposable
public abstract class DrawingContext : System.Windows.Threading.DispatcherObject, IDisposable
type DrawingContext = class
inherit DispatcherObject
interface IDisposable
Public MustInherit Class DrawingContext
Inherits DispatcherObject
Implements IDisposable
- 継承
- 実装
例
次の例では、DrawingVisual から DrawingContext を取得し、それを四角形の描画に使用しています。The following example retrieves a DrawingContext from a DrawingVisual and uses it to draw a rectangle.
// Create a DrawingVisual that contains a rectangle.
private DrawingVisual CreateDrawingVisualRectangle()
{
DrawingVisual drawingVisual = new DrawingVisual();
// Retrieve the DrawingContext in order to create new drawing content.
DrawingContext drawingContext = drawingVisual.RenderOpen();
// Create a rectangle and draw it in the DrawingContext.
Rect rect = new Rect(new System.Windows.Point(160, 100), new System.Windows.Size(320, 80));
drawingContext.DrawRectangle(System.Windows.Media.Brushes.LightBlue, (System.Windows.Media.Pen)null, rect);
// Persist the drawing content.
drawingContext.Close();
return drawingVisual;
}
' Create a DrawingVisual that contains a rectangle.
Private Function CreateDrawingVisualRectangle() As DrawingVisual
Dim drawingVisual As New DrawingVisual()
' Retrieve the DrawingContext in order to create new drawing content.
Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()
' Create a rectangle and draw it in the DrawingContext.
Dim rect As New Rect(New Point(160, 100), New Size(320, 80))
drawingContext.DrawRectangle(Brushes.LightBlue, CType(Nothing, Pen), rect)
' Persist the drawing content.
drawingContext.Close()
Return drawingVisual
End Function
次の例では PushOpacity 、、、およびの各コマンドについて説明し PushEffect Pop ます。The next example demonstrates the PushOpacity, PushEffect, and Pop commands. は DrawingContext から取得され、 DrawingGroup コントロールを使用して表示され Image ます。The DrawingContext is obtained from a DrawingGroup and displayed using an Image control.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Media.Effects;
namespace SDKSample
{
public class PushEffectExample : Page
{
public PushEffectExample()
{
Pen shapeOutlinePen = new Pen(Brushes.Black, 2);
shapeOutlinePen.Freeze();
// Create a DrawingGroup
DrawingGroup dGroup = new DrawingGroup();
// Obtain a DrawingContext from
// the DrawingGroup.
using (DrawingContext dc = dGroup.Open())
{
// Draw a rectangle at full opacity.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(0, 0, 25, 25));
// Push an opacity change of 0.5.
// The opacity of each subsequent drawing will
// will be multiplied by 0.5.
dc.PushOpacity(0.5);
// This rectangle is drawn at 50% opacity.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(25, 25, 25, 25));
// Blurs subsquent drawings.
dc.PushEffect(new BlurBitmapEffect(), null);
// This rectangle is blurred and drawn at 50% opacity (0.5 x 0.5).
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(50, 50, 25, 25));
// This rectangle is also blurred and drawn at 50% opacity.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(75, 75, 25, 25));
// Stop applying the blur to subsquent drawings.
dc.Pop();
// This rectangle is drawn at 50% opacity with no blur effect.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(100, 100, 25, 25));
}
// Display the drawing using an image control.
Image theImage = new Image();
DrawingImage dImageSource = new DrawingImage(dGroup);
theImage.Source = dImageSource;
this.Content = theImage;
}
}
}
Imports System.Windows.Media.Animation
Imports System.Windows.Media.Effects
Namespace SDKSample
Public Class PushEffectExample
Inherits Page
Public Sub New()
Dim shapeOutlinePen As New Pen(Brushes.Black, 2)
shapeOutlinePen.Freeze()
' Create a DrawingGroup
Dim dGroup As New DrawingGroup()
' Obtain a DrawingContext from
' the DrawingGroup.
Using dc As DrawingContext = dGroup.Open()
' Draw a rectangle at full opacity.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(0, 0, 25, 25))
' Push an opacity change of 0.5.
' The opacity of each subsequent drawing will
' will be multiplied by 0.5.
dc.PushOpacity(0.5)
' This rectangle is drawn at 50% opacity.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(25, 25, 25, 25))
' Blurs subsquent drawings.
dc.PushEffect(New BlurBitmapEffect(), Nothing)
' This rectangle is blurred and drawn at 50% opacity (0.5 x 0.5).
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(50, 50, 25, 25))
' This rectangle is also blurred and drawn at 50% opacity.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(75, 75, 25, 25))
' Stop applying the blur to subsquent drawings.
dc.Pop()
' This rectangle is drawn at 50% opacity with no blur effect.
dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(100, 100, 25, 25))
End Using
' Display the drawing using an image control.
Dim theImage As New Image()
Dim dImageSource As New DrawingImage(dGroup)
theImage.Source = dImageSource
Me.Content = theImage
End Sub
End Class
End Namespace
注釈
ビジュアルコンテンツを使用し DrawingContext てまたはにデータを設定するには、を使用し Visual Drawing ます。Use a DrawingContext to populate a Visual or a Drawing with visual content.
DrawingContext描画メソッドは、型の描画メソッドと同様に表示され System.Drawing.Graphics ますが、動作が非常に異なります。 DrawingContext は、保持モードのグラフィックスシステムで使用されます。一方、 System.Drawing.Graphics 型はイミディエイトモードのグラフィックスシステムで使用されます。Although the DrawingContext draw methods appear similar to the draw methods of the System.Drawing.Graphics type, they function very differently: DrawingContext is used with a retained mode graphics system, while the System.Drawing.Graphics type is used with an immediate mode graphics system. DrawingContext オブジェクトの描画コマンドを使用すると、実際には、レンダリング命令のセットが保存され (ただし、厳密な格納メカニズムは DrawingContext を提供するオブジェクトの型に依存します)、後でグラフィックス システムによって使用されます。画面にリアルタイムで描画されることはありません。When you use a DrawingContext object's draw commands, you are actually storing a set of rendering instructions (although the exact storage mechanism depends on the type of object that supplies the DrawingContext) that will later be used by the graphics system; you are not drawing to the screen in real-time. Windows Presentation Foundation (WPF) グラフィックスシステムの動作の詳細については、「 Wpf グラフィックスレンダリングの概要」を参照してください。For more information about how the Windows Presentation Foundation (WPF) graphics system works, see WPF Graphics Rendering Overview.
DrawingContext を直接インスタンス化することはできません。ただし、描画コンテキストは、特定のメソッド (DrawingGroup.Open や DrawingVisual.RenderOpen など) から取得できます。You never directly instantiate a DrawingContext; you can, however, acquire a drawing context from certain methods, such as DrawingGroup.Open and DrawingVisual.RenderOpen.
プロパティ
Dispatcher |
この Dispatcher が関連付けられている DispatcherObject を取得します。Gets the Dispatcher this DispatcherObject is associated with. (継承元 DispatcherObject) |
メソッド
CheckAccess() |
呼び出し元のスレッドがこの DispatcherObject にアクセスできるかどうかを確認します。Determines whether the calling thread has access to this DispatcherObject. (継承元 DispatcherObject) |
Close() |
DrawingContext を閉じてコンテンツをフラッシュします。Closes the DrawingContext and flushes the content. それ以降、DrawingContext は変更できなくなります。Afterward, the DrawingContext cannot be modified. |
DisposeCore() |
DrawingContext によって使用されているすべてのリソースを解放します。Releases all resources used by the DrawingContext. |
DrawDrawing(Drawing) |
指定した Drawing オブジェクトを描画します。Draws the specified Drawing object. |
DrawEllipse(Brush, Pen, Point, AnimationClock, Double, AnimationClock, Double, AnimationClock) |
指定した Brush および Pen を使用して楕円を描画し、特定のアニメーション クロックを適用します。Draws an ellipse with the specified Brush and Pen and applies the specified animation clocks. |
DrawEllipse(Brush, Pen, Point, Double, Double) |
指定した Brush および Pen を使用して楕円を描画します。Draws an ellipse with the specified Brush and Pen. |
DrawGeometry(Brush, Pen, Geometry) |
指定された Brush と Pen を使用して、指定された Geometry を描画します。Draws the specified Geometry using the specified Brush and Pen. |
DrawGlyphRun(Brush, GlyphRun) |
指定したテキストを描画します。Draws the specified text. |
DrawImage(ImageSource, Rect) |
指定した Rect で定義されている領域にイメージを描画します。Draws an image into the region defined by the specified Rect. |
DrawImage(ImageSource, Rect, AnimationClock) |
指定した Rect で定義されている領域にイメージを描画し、指定したアニメーション クロックを適用します。Draws an image into the region defined by the specified Rect and applies the specified animation clock. |
DrawLine(Pen, Point, AnimationClock, Point, AnimationClock) |
指定した Pen を使用して、特定のポイント間に線を描画し、特定のアニメーション クロックを適用します。Draws a line between the specified points using the specified Pen and applies the specified animation clocks. |
DrawLine(Pen, Point, Point) |
指定した Pen を使用して指定したポイントの間の線を描画します。Draws a line between the specified points using the specified Pen. |
DrawRectangle(Brush, Pen, Rect) |
指定した Brush および Pen を使用して四角形を描画します。Draws a rectangle with the specified Brush and Pen. ペンとブラシに |
DrawRectangle(Brush, Pen, Rect, AnimationClock) |
指定した Brush および Pen を使用して四角形を描画し、特定のアニメーション クロックを適用します。Draws a rectangle with the specified Brush and Pen and applies the specified animation clocks. |
DrawRoundedRectangle(Brush, Pen, Rect, AnimationClock, Double, AnimationClock, Double, AnimationClock) |
指定した Brush および Pen を使用して丸みのある四角形を描画し、特定のアニメーション クロックを適用します。Draws a rounded rectangle with the specified Brush and Pen and applies the specified animation clocks. |
DrawRoundedRectangle(Brush, Pen, Rect, Double, Double) |
指定した Brush および Pen を使用して丸みのある四角形を描画します。Draws a rounded rectangle with the specified Brush and Pen. |
DrawText(FormattedText, Point) |
書式設定されたテキストを指定した位置に描画します。Draws formatted text at the specified location. |
DrawVideo(MediaPlayer, Rect) |
指定した領域にビデオを描画します。Draws a video into the specified region. |
DrawVideo(MediaPlayer, Rect, AnimationClock) |
指定した領域にビデオを描画し、指定したアニメーション クロックを適用します。Draws a video into the specified region and applies the specified animation clock. |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object. (継承元 Object) |
GetHashCode() |
既定のハッシュ関数として機能します。Serves as the default hash function. (継承元 Object) |
GetType() |
現在のインスタンスの Type を取得します。Gets the Type of the current instance. (継承元 Object) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object. (継承元 Object) |
Pop() |
描画コンテキストにプッシュされた最後の不透明マスク、不透明度、クリップ、効果、または変換操作をポップします。Pops the last opacity mask, opacity, clip, effect, or transform operation that was pushed onto the drawing context. |
PushClip(Geometry) |
指定したクリップ領域を描画コンテキストにプッシュします。Pushes the specified clip region onto the drawing context. |
PushEffect(BitmapEffect, BitmapEffectInput) |
互換性のために残されています。
指定した BitmapEffect を描画コンテキストにプッシュします。Pushes the specified BitmapEffect onto the drawing context. |
PushGuidelineSet(GuidelineSet) |
指定した GuidelineSet を描画コンテキストにプッシュします。Pushes the specified GuidelineSet onto the drawing context. |
PushOpacity(Double) |
指定した透過度設定を描画コンテキストにプッシュします。Pushes the specified opacity setting onto the drawing context. |
PushOpacity(Double, AnimationClock) |
指定した透過度設定を描画コンテキストにプッシュし、指定したアニメーション クロックを適用します。Pushes the specified opacity setting onto the drawing context and applies the specified animation clock. |
PushOpacityMask(Brush) |
指定した不透明マスクを描画コンテキストにプッシュします。Pushes the specified opacity mask onto the drawing context. |
PushTransform(Transform) |
指定した Transform を描画コンテキストにプッシュします。Pushes the specified Transform onto the drawing context. |
ToString() |
現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object. (継承元 Object) |
VerifyAccess() |
呼び出し元のスレッドがこの DispatcherObject にアクセスできるように強制します。Enforces that the calling thread has access to this DispatcherObject. (継承元 DispatcherObject) |
VerifyApiNonstructuralChange() |
このメンバーは、WPFWPF インフラストラクチャをサポートしますが、独自に作成したコードから直接使用するためのものではありません。This member supports the WPFWPF infrastructure and is not intended to be used directly from your code. |
明示的なインターフェイスの実装
IDisposable.Dispose() |
このメンバーは、Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) インフラストラクチャをサポートしますが、独自に作成したコードから直接使用するためのものではありません。This member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. |