Graphics.GetHalftonePalette Yöntem

Tanım

Geçerli Windows yarım ton paletinin tutamacını alır.

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

Döndürülenler

IntPtr

nativeint

Palet tutamacını belirten iç işaretçi.

Örnekler

Aşağıdaki kod örneği, Windows Forms ile kullanılmak üzere tasarlanmıştır ve olay işleyicisinin Paint bir parametresi olan gerektirir.PaintEventArgse Kod aşağıdaki eylemleri gerçekleştirir:

  • Gerekli GDI işlevlerini içeren Windows DLL dosyası gdi32.dll için birlikte çalışabilirlik DllImportAttribute özniteliklerini tanımlar.

  • Bu DLL'deki SelectPalette ve RealizePalette işlevlerini dış olarak tanımlar.

  • Mevcut bir görüntü dosyasından (örnek kod dosyasıyla aynı klasörde olması gerekir) SampImag.jpg bir görüntü oluşturur ve görüntüyü ekrana çizer.

  • İç işaretçi türü değişkenleri oluşturur ve değerlerini tutamaçta sırasıyla grafik nesnesine ve geçerli Windows yarım ton paletine ayarlar.

  • Noktalı ton paletini seçer ve fark eder.

  • parametresini hdc kullanarak yeni bir grafik nesnesi oluşturur.

  • Görüntüyü yeniden çizer.

  • Tanıtıcıyı cihaz bağlamı için serbest bırakır.

Sonuç, örnek görüntünün iki işlemesidir: biri 16 bit paletli, diğeri 8 bit paletli.

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

Açıklamalar

Yöntemin GetHalftonePalette amacı, ekranda piksel başına 8 bit kullanıldığında GDI+'nın daha kaliteli bir noktalı ton üretmesini sağlamaktır. Noktalı ton paletini kullanarak bir görüntü görüntülemek için aşağıdaki yordamı kullanın.

Şunlara uygulanır