Graphics.GetHalftonePalette 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 Windows 하프톤 팔레트에 대한 핸들을 가져옵니다.
public:
static IntPtr GetHalftonePalette();
public static IntPtr GetHalftonePalette ();
static member GetHalftonePalette : unit -> nativeint
Public Shared Function GetHalftonePalette () As IntPtr
반환
nativeint
팔레트에 대한 핸들을 지정하는 내부 포인터입니다.
예제
다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse
코드는 다음 작업을 수행합니다.
필요한 GDI 함수를 포함하는 Windows DLL 파일 gdi32.dll 대한 상호 운용성 DllImportAttribute 특성을 정의합니다.
해당 DLL의
SelectPalette
및RealizePalette
함수를 외부로 정의합니다.기존 이미지 파일 SampImag.jpg 이미지를 만들고(예제 코드 파일과 동일한 폴더에 있어야 합니다) 이미지를 화면에 그립니다.
내부 포인터 형식 변수를 만들고 해당 값을 그래픽 개체의 핸들과 현재 Windows 하프톤 팔레트로 각각 설정합니다.
하프톤 팔레트를 선택하고 실현합니다.
매개 변수를 사용하여 새 그래픽 개체를
hdc
만듭니다.이미지를 다시 그립니다.
디바이스 컨텍스트에 대 한 핸들을 해제합니다.
그 결과 샘플 이미지의 두 가지 렌더링, 즉 16비트 팔레트와 8비트 팔레트가 있는 렌더링이 생성됩니다.
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
설명
이 메서드의 GetHalftonePalette 목적은 디스플레이에서 픽셀당 8비트 사용 시 GDI+가 더 나은 품질 하프톤을 생성할 수 있도록 하는 것입니다. 하프톤 팔레트를 사용하여 이미지를 표시하려면 다음 절차를 사용합니다.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기