Graphics.GetHalftonePalette Método

Definición

Obtiene un identificador de la paleta actual de medios tonos de Windows.

public:
 static IntPtr GetHalftonePalette();
public static IntPtr GetHalftonePalette ();
static member GetHalftonePalette : unit -> nativeint
Public Shared Function GetHalftonePalette () As IntPtr

Devoluciones

IntPtr

nativeint

Puntero interno que especifica el identificador de la paleta.

Ejemplos

El ejemplo de código siguiente está diseñado para su uso con Windows Forms y requiere PaintEventArgse, que es un parámetro del Paint controlador de eventos. El código realiza las siguientes acciones:

  • Define los atributos de interoperabilidad DllImportAttribute para el archivo DLL de Windows gdi32.dll, que contiene las funciones GDI necesarias.

  • Define las SelectPalette funciones y RealizePalette de esa DLL como externas.

  • Crea una imagen a partir de un archivo de imagen existente SampImag.jpg (que debe estar en la misma carpeta que el archivo de código de ejemplo) y dibuja la imagen en la pantalla.

  • Crea variables de tipo de puntero interno y establece sus valores en el identificador del objeto gráfico y en la paleta de media tono de Windows actual, respectivamente.

  • Selecciona y se da cuenta de la paleta de medio tono.

  • Crea un nuevo objeto gráfico mediante el hdc parámetro .

  • Dibuja la imagen de nuevo.

  • Libera el identificador en el contexto del dispositivo.

El resultado es dos representaciones de la imagen de ejemplo: una con la paleta de 16 bits y otra con la paleta de 8 bits.

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

Comentarios

El propósito del GetHalftonePalette método es permitir que GDI+ genere un medio tono de calidad mejor cuando la pantalla usa 8 bits por píxel. Para mostrar una imagen mediante la paleta de medio tono, use el procedimiento siguiente.

Se aplica a