Graphics.FromHdc メソッド

定義

指定したハンドルからデバイス コンテキストに新しい Graphics を作成します。

オーバーロード

名前 説明
FromHdc(IntPtr, IntPtr)

指定したハンドルからデバイス コンテキストへの新しい Graphics を作成し、デバイスへのハンドルを作成します。

FromHdc(IntPtr)

指定したハンドルからデバイス コンテキストに新しい Graphics を作成します。

FromHdc(IntPtr, IntPtr)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したハンドルからデバイス コンテキストへの新しい Graphics を作成し、デバイスへのハンドルを作成します。

public:
 static System::Drawing::Graphics ^ FromHdc(IntPtr hdc, IntPtr hdevice);
public static System.Drawing.Graphics FromHdc(IntPtr hdc, IntPtr hdevice);
static member FromHdc : nativeint * nativeint -> System.Drawing.Graphics
Public Shared Function FromHdc (hdc As IntPtr, hdevice As IntPtr) As Graphics

パラメーター

hdc
IntPtr

nativeint

デバイス コンテキストへのハンドル。

hdevice
IntPtr

nativeint

デバイスへのハンドル。

返品

このメソッドは、指定したデバイス コンテキストとデバイスの新しい Graphics を返します。

注釈

Dispose メソッドによって作成されたGraphicsと関連リソースを解放するには、常に FromHdc メソッドを呼び出す必要があります。

ディスプレイ デバイスに ICM カラー プロファイルが関連付けられている場合でも、GDI+ は既定でそのプロファイルを使用しません。 Graphicsに対して ICM を有効にするには、HDC (およびICM_ON) をGraphics関数に渡した後、HDC からSetICMModeを構築します。 その後、 Graphics によって行われる描画は、ディスプレイ デバイスに関連付けられている ICM プロファイルに従って調整されます。 ICM を有効にすると、パフォーマンスが低下します。

FromHdc呼び出し時のデバイス コンテキスト (マッピング モード、論理ユニットなど) の状態は、Graphicsによって実行されるレンダリングに影響する可能性があります。

デバイス ハンドルは、通常、特定のプリンター機能のクエリに使用されます。

適用対象

FromHdc(IntPtr)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定したハンドルからデバイス コンテキストに新しい Graphics を作成します。

public:
 static System::Drawing::Graphics ^ FromHdc(IntPtr hdc);
public static System.Drawing.Graphics FromHdc(IntPtr hdc);
static member FromHdc : nativeint -> System.Drawing.Graphics
Public Shared Function FromHdc (hdc As IntPtr) As Graphics

パラメーター

hdc
IntPtr

nativeint

デバイス コンテキストへのハンドル。

返品

このメソッドは、指定したデバイス コンテキストの新しい Graphics を返します。

次のコード例は、Windows フォームで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 このコードでは、次のアクションが実行されます。

  • hdc内部ポインター型変数を作成し、フォームのグラフィックス オブジェクトのデバイス コンテキストのハンドルに設定します。

  • hdcを使用して新しいグラフィックス オブジェクトを作成します。

  • 新しいグラフィックス オブジェクト (画面上) を使用して四角形を描画します。

  • hdcを使用して新しいグラフィックス オブジェクトを解放します。

public:
   void FromHdcHdc( PaintEventArgs^ e )
   {
      // Get handle to device context.
      IntPtr hdc = e->Graphics->GetHdc();

      // Create new graphics object using handle to device context.
      Graphics^ newGraphics = Graphics::FromHdc( hdc );

      // Draw rectangle to screen.
      newGraphics->DrawRectangle( gcnew Pen( Color::Red,3.0f ), 0, 0, 200, 100 );

      // Release handle to device context and dispose of the      // Graphics object
      e->Graphics->ReleaseHdc( hdc );
      delete newGraphics;
   }
private void FromHdcHdc(PaintEventArgs e)
{
    // Get handle to device context.
    IntPtr hdc = e.Graphics.GetHdc();

    // Create new graphics object using handle to device context.
    Graphics newGraphics = Graphics.FromHdc(hdc);

    // Draw rectangle to screen.
    newGraphics.DrawRectangle(new Pen(Color.Red, 3), 0, 0, 200, 100);

    // Release handle to device context and dispose of the      // Graphics object
    e.Graphics.ReleaseHdc(hdc);
    newGraphics.Dispose();
}
<System.Security.Permissions.SecurityPermission( _
System.Security.Permissions.SecurityAction.LinkDemand, Flags := _
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
Private Sub FromHdcHdc(ByVal e As PaintEventArgs)

    ' Get handle to device context.
    Dim hdc As IntPtr = e.Graphics.GetHdc()

    ' Create new graphics object using handle to device context.
    Dim newGraphics As Graphics = Graphics.FromHdc(hdc)

    ' Draw rectangle to screen.
    newGraphics.DrawRectangle(New Pen(Color.Red, 3), 0, 0, 200, 100)

    ' Release handle to device context and dispose of the Graphics 	' object
    e.Graphics.ReleaseHdc(hdc)
    newGraphics.Dispose()
End Sub

注釈

Dispose メソッドによって作成されたGraphicsと関連リソースを解放するには、常に FromHdc メソッドを呼び出す必要があります。

ディスプレイ デバイスに ICM カラー プロファイルが関連付けられている場合でも、GDI+ は既定でそのプロファイルを使用しません。 Graphicsに対して ICM を有効にするには、HDC (およびICM_ON) をGraphics関数に渡した後、HDC からSetICMModeを構築します。 その後、 Graphics によって行われる描画は、ディスプレイ デバイスに関連付けられている ICM プロファイルに従って調整されます。 ICM を有効にすると、パフォーマンスが低下します。

FromHdc呼び出し時のデバイス コンテキスト (マッピング モード、論理ユニットなど) の状態は、Graphicsによって実行されるレンダリングに影響する可能性があります。

適用対象