Graphics.GetHalftonePalette Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar ett handtag till den aktuella Windows halvtonpalett.
public:
static IntPtr GetHalftonePalette();
public static IntPtr GetHalftonePalette();
static member GetHalftonePalette : unit -> nativeint
Public Shared Function GetHalftonePalette () As IntPtr
Returer
nativeint
Intern pekare som anger handtaget till paletten.
Exempel
Följande kodexempel är utformat för användning med Windows Forms och kräver PaintEventArgse, vilket är en parameter för händelsehanteraren Paint. Koden utför följande åtgärder:
Definierar samverkan DllImportAttribute attribut för Windows DLL-filen gdi32.dll, som innehåller nödvändiga GDI-funktioner.
Definierar
SelectPalettefunktionerna ochRealizePalettei DLL:en som externa.Skapar en bild från en befintlig bildfil SampImag.jpg (som måste finnas i samma mapp som exempelkodfilen) och ritar bilden till skärmen.
Skapar interna pekartypvariabler och anger deras värden till handtaget till grafikobjektet och till den aktuella Windows halvtonpaletten.
Väljer och förverkligar halvtonpaletten.
Skapar ett nytt grafikobjekt med hjälp av parametern
hdc.Ritar bilden igen.
Släpper handtaget till enhetskontexten.
Resultatet är två återgivningar av exempelbilden: en med 16-bitarspaletten och en med 8-bitarspaletten.
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
Kommentarer
Syftet med metoden är att göra det möjligt för GDI+ att producera en halvton av GetHalftonePalette bättre kvalitet när skärmen använder 8 bitar per pixel. Om du vill visa en bild med hjälp av halvtonpaletten använder du följande procedur.