Graphics.GetHalftonePalette Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Ruft ein Handle für die aktuelle Windows-Halbtonpalette ab.
public:
static IntPtr GetHalftonePalette();
public static IntPtr GetHalftonePalette ();
static member GetHalftonePalette : unit -> nativeint
Public Shared Function GetHalftonePalette () As IntPtr
Gibt zurück
nativeint
Interner Zeiger, der das Handle für die Palette angibt.
Beispiele
Das folgende Codebeispiel ist für die Verwendung mit Windows Forms konzipiert und erfordert PaintEventArgse
, was ein Parameter des Paint Ereignishandlers ist. Der Code führt die folgenden Aktionen aus:
Definiert Interoperabilitätsattribute DllImportAttribute für die Windows-DLL-Datei gdi32.dll, die die erforderlichen GDI-Funktionen enthält.
Definiert die
SelectPalette
Funktionen undRealizePalette
in dieser DLL als extern.Erstellt ein Bild aus einer vorhandenen Bilddatei SampImag.jpg (die sich im selben Ordner wie die Beispielcodedatei befinden muss) und zeichnet das Bild auf den Bildschirm.
Erstellt interne Zeigertypvariablen und legt deren Werte auf das Handle für das Grafikobjekt bzw. die aktuelle Windows-Halbtonpalette fest.
Wählt die Halbtonpalette aus und realisiert sie.
Erstellt mithilfe des
hdc
Parameters ein neues Grafikobjekt.Zeichnet das Bild erneut.
Gibt das Handle für den Gerätekontext frei.
Das Ergebnis sind zwei Renderings des Beispielbilds: eines mit der 16-Bit-Palette und eines mit der 8-Bit-Palette.
private:
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static IntPtr SelectPalette( IntPtr hdc, IntPtr htPalette, bool bForceBackground );
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static int RealizePalette( IntPtr hdc );
public:
void GetHalftonePaletteVoid( PaintEventArgs^ e )
{
// Create and draw image.
Image^ imageFile = Image::FromFile( "SampImag.jpg" );
e->Graphics->DrawImage( imageFile, 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 );
}
[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);
private 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);
}
<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)> _
Private 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
Hinweise
Der Zweck der GetHalftonePalette Methode besteht darin, GDI+ zu ermöglichen, einen Halbton von besserer Qualität zu erzeugen, wenn die Anzeige 8 Bits pro Pixel verwendet. Gehen Sie wie folgt vor, um ein Bild mit der Halbtonpalette anzuzeigen.
Gilt für:
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für