Graphics.GetHalftonePalette メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim returnValue As IntPtr returnValue = Graphics.GetHalftonePalette
パレットを識別するハンドルを指定する内部ポインタ。

GetHalftonePalette メソッドの目的は、8 ビット/ピクセルの表示を使用する場合に GDI+ で生成するハーフトーンの品質を向上させることです。ハーフトーン パレットを使用してイメージを表示するには、次の手順に従います。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
-
必要な GDI 関数が格納された、Windows DLL ファイル gdi32.dll の相互運用性 DllImportAttribute 属性を定義します。
-
既存のイメージ ファイル SampImag.jpg (サンプルのコード ファイルと同じフォルダに置く必要があります) からイメージを作成し、画面にそのイメージを描画します。
-
内部ポインタ型変数を作成し、それらの値をグラフィックス オブジェクトを識別するハンドルと、現在の Windows ハーフトーン パレットを識別するハンドルにそれぞれ設定します。
16 ビット パレットと 8 ビット パレットを使用して、サンプル イメージの 2 つのレンダリングが生成されます。
<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _ Private Shared Function SelectPalette(ByVal hdc As IntPtr, _ ByVal htPalette As IntPtr, ByVal bForceBackground As Boolean) As IntPtr End Function <System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _ Private Shared Function RealizePalette(ByVal hdc As IntPtr) As Integer End Function <System.Security.Permissions.SecurityPermission( _ System.Security.Permissions.SecurityAction.LinkDemand, Flags := _ System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _ Public Sub GetHalftonePaletteVoid(ByVal e As PaintEventArgs) ' Create and draw image. Dim imageFile As Image = Image.FromFile("SampImag.jpg") e.Graphics.DrawImage(imageFile, New Point(0, 0)) ' Get handle to device context. Dim hdc As IntPtr = e.Graphics.GetHdc() ' Get handle to halftone palette. Dim htPalette As IntPtr = Graphics.GetHalftonePalette() ' Select and realize new palette. SelectPalette(hdc, htPalette, True) RealizePalette(hdc) ' Create new graphics object. Dim newGraphics As Graphics = Graphics.FromHdc(hdc) ' Draw image with new palette. newGraphics.DrawImage(imageFile, 300, 0) ' Release handle to device context. e.Graphics.ReleaseHdc(hdc) End Sub
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")] private static extern IntPtr SelectPalette( IntPtr hdc, IntPtr htPalette, bool bForceBackground); [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")] private static extern int RealizePalette(IntPtr hdc); [System.Security.Permissions.SecurityPermission( System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] public void GetHalftonePaletteVoid(PaintEventArgs e) { // Create and draw image. Image imageFile = Image.FromFile("SampImag.jpg"); e.Graphics.DrawImage(imageFile, new Point(0, 0)); // Get handle to device context. IntPtr hdc = e.Graphics.GetHdc(); // Get handle to halftone palette. IntPtr htPalette = Graphics.GetHalftonePalette(); // Select and realize new palette. SelectPalette(hdc, htPalette, true); RealizePalette(hdc); // Create new graphics object. Graphics newGraphics = Graphics.FromHdc(hdc); // Draw image with new palette. newGraphics.DrawImage(imageFile, 300, 0); // Release handle to device context. e.Graphics.ReleaseHdc(hdc); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGraphics.GetHalftonePalette メソッドを検索する場合は、下記のリンクをクリックしてください。

- Graphics.GetHalftonePalette メソッドのページへのリンク