Graphics.GetHalftonePalette Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém um identificador para a paleta de meio-tom atual do Windows.
public:
static IntPtr GetHalftonePalette();
public static IntPtr GetHalftonePalette ();
static member GetHalftonePalette : unit -> nativeint
Public Shared Function GetHalftonePalette () As IntPtr
Retornos
nativeint
Ponteiro interno que especifica o identificador para a paleta.
Exemplos
O exemplo de código a seguir foi projetado para uso com Windows Forms e requer PaintEventArgse
, que é um parâmetro do Paint manipulador de eventos. O código executa as seguintes ações:
Define atributos de interoperabilidade DllImportAttribute para o arquivo DLL do Windows gdi32.dll, que contém as funções GDI necessárias.
Define as
SelectPalette
funções eRealizePalette
nessa DLL como externas.Cria uma imagem de um arquivo de imagem existente SampImag.jpg (que deve estar na mesma pasta que o arquivo de código de exemplo) e desenha a imagem para a tela.
Cria variáveis de tipo de ponteiro interno e define seus valores para o identificador para o objeto gráfico e para a paleta de meio tom do Windows atual, respectivamente.
Seleciona e percebe a paleta de meio tom.
Cria um novo objeto gráfico usando o
hdc
parâmetro .Desenha a imagem novamente.
Libera o identificador para o contexto do dispositivo.
O resultado são duas renderizações da imagem de exemplo: uma com a paleta de 16 bits e outra com a 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
Comentários
A finalidade do GetHalftonePalette método é permitir que o GDI+ produza um meio-tom de melhor qualidade quando a tela usa 8 bits por pixel. Para exibir uma imagem usando a paleta de meio tom, use o procedimento a seguir.
Aplica-se a
Comentários
https://aka.ms/ContentUserFeedback.
Em breve: Ao longo de 2024, eliminaremos os problemas do GitHub como o mecanismo de comentários para conteúdo e o substituiremos por um novo sistema de comentários. Para obter mais informações, consulteEnviar e exibir comentários de