Graphics.GetHalftonePalette Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u een ingang naar het huidige Windows halftoonpalet.
public:
static IntPtr GetHalftonePalette();
public static IntPtr GetHalftonePalette();
static member GetHalftonePalette : unit -> nativeint
Public Shared Function GetHalftonePalette () As IntPtr
Retouren
nativeint
Interne aanwijzer waarmee de greep naar het palet wordt opgegeven.
Voorbeelden
Het volgende codevoorbeeld is ontworpen voor gebruik met Windows Forms en vereist PaintEventArgse, een parameter van de Paint gebeurtenis-handler. De code voert de volgende acties uit:
Definieert interoperabiliteit DllImportAttribute kenmerken voor het Windows DLL-bestand gdi32.dll, dat de benodigde GDI-functies bevat.
Definieert de
SelectPaletteenRealizePalettefuncties in dat DLL-bestand als extern.Hiermee maakt u een afbeelding van een bestaand afbeeldingsbestand SampImag.jpg (die zich in dezelfde map als het voorbeeldcodebestand moet bevinden) en tekent u de afbeelding naar het scherm.
Hiermee maakt u interne variabelen van het type aanwijzer en stelt u de bijbehorende waarden in op de ingang voor het grafische object en op het huidige Windows halftoonpalet.
Selecteert en realiseert het halftoonpalet.
Hiermee maakt u een nieuw grafisch object met behulp van de
hdcparameter.Hiermee tekent u de afbeelding opnieuw.
Hiermee wordt de ingang naar de apparaatcontext vrijgegeven.
Het resultaat is twee renderings van de voorbeeldafbeelding: één met het 16-bits palet en één met het 8-bits palet.
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
Opmerkingen
Het doel van de GetHalftonePalette methode is om GDI+ in staat te stellen om een betere kwaliteit halfton te produceren wanneer het scherm 8 bits per pixel gebruikt. Als u een afbeelding wilt weergeven met behulp van het halftoonpalet, gebruikt u de volgende procedure.