다음을 통해 공유


ImageAttributes::ClearColorKey 메서드(gdiplusimageattributes.h)

ImageAttributes::ClearColorKey 메서드는 지정된 범주에 대한 색 키(투명도 범위)를 지웁니다.

구문

Status ClearColorKey(
  [in, optional] ColorAdjustType type
);

매개 변수

[in, optional] type

형식: ColorAdjustType

색 키가 지워지는 범주를 지정하는 ColorAdjustType 열거형의 요소입니다. 기본값은 ColorAdjustTypeDefault입니다.

반환 값

형식: 상태

메서드가 성공하면 Status 열거형의 요소인 확인을 반환합니다.

메서드가 실패하면 Status 열거형의 다른 요소 중 하나를 반환합니다.

설명

ImageAttributes 개체는 기본, 비트맵, 브러시, 펜 및 텍스트의 다섯 가지 조정 범주에 대한 색 및 회색조 설정을 유지합니다. 예를 들어 기본 범주에 대해 하나의 색 키를 지정하고 비트맵 범주에 다른 색 키를 지정하고 펜 범주에 대해 다른 색 키를 지정할 수 있습니다.

기본 색 및 회색조 조정 설정은 자체 조정 설정이 없는 모든 범주에 적용됩니다. 예를 들어 펜 범주에 대한 조정 설정을 지정하지 않으면 기본 설정이 펜 범주에 적용됩니다.

특정 범주에 대한 색 또는 회색조 조정 설정을 지정하는 즉시 기본 조정 설정이 해당 범주에 더 이상 적용되지 않습니다. 예를 들어 200부터 255까지 빨간색 구성 요소가 있는 모든 색을 투명하게 만들고 기본 감마 값 1.8을 지정하는 기본 색 키를 지정한다고 가정합니다. ImageAttributes::SetColorKey를 호출하여 펜 범주의 색 키를 설정하는 경우 기본 색 키와 기본 감마 값이 펜에 적용되지 않습니다. 나중에 ImageAttributes::ClearColorKey를 호출하여 펜 색 키를 지우면 펜 범주가 기본 색 키에 되돌리기 않습니다. 대신 펜 범주에는 색 키가 없습니다. 마찬가지로 펜 범주는 기본 감마 값으로 되돌리기 않습니다. 대신 펜 범주에는 감마 값이 없습니다.

예제

다음 예제에서는 .emf 파일에서 Image 개체를 만듭니다. 또한 이 코드는 ImageAttributes 개체를 만듭니다. ImageAttributes::SetColorKey에 대한 첫 번째 호출은 80에서 120까지의 빨간색 구성 요소가 있는 색이 투명하도록 ImageAttributes 개체의 기본 색 키를 설정합니다. ImageAttributes::SetColorKey에 대한 두 번째 호출은 135부터 175까지 빨간색 구성 요소가 있는 모든 색이 투명하도록 ImageAttributes 개체의 펜 색 키를 설정합니다.

코드는 DrawImage 를 한 번 호출하여 색 조정 없이 이미지를 그립니다. 그런 다음, 코드는 Image 개체의 주소와 ImageAttributes 개체의 주소를 전달할 때마다 DrawImage를 세 번 더 호출합니다. 이미지를 두 번째로 그릴 때(기본 색 키를 설정하는 호출 후) 80에서 120까지의 모든 빨간색은 투명합니다. 세 번째로 이미지를 그릴 때(펜 색 키를 설정하는 호출 후) 펜으로 그린 135에서 175까지의 모든 빨간색은 투명합니다. 또한 펜으로 그려지지 않은 80에서 120까지의 모든 빨간색은 투명합니다. 이미지를 네 번째로 그릴 때( ImageAttributes::ClearColorKey 호출 후) 펜으로 그린 빨간색은 투명하지 않습니다. 또한 펜으로 그려지지 않은 80에서 120까지의 모든 빨간색은 투명합니다.


VOID Example_SetClearColorKey(HDC hdc)
{
   Graphics graphics(hdc);

   Image image(L"TestMetafile5.emf");
   ImageAttributes imAtt;

   // Draw the image (metafile) using no color adjustment.
   graphics.DrawImage(
      &image,
      Rect(0, 0, image.GetWidth(), image.GetHeight()),  // dest rect
      0, 0, image.GetWidth(), image.GetHeight(),        // source rect
      UnitPixel);

   // Set the default color key.
   imAtt.SetColorKey(
      Color(0, 80, 0, 0),
      Color(255, 120, 255, 255),
      ColorAdjustTypeDefault);

   // Draw the image (metafile) using default color adjustment.
   // Colors with red components from 80 through 120 are transparent.
   graphics.DrawImage(
      &image,
      Rect(0, 100, image.GetWidth(), image.GetHeight()),  // dest rect
      0, 0, image.GetWidth(), image.GetHeight(),          // source rect
      UnitPixel,
      &imAtt);

   // Set the pen color key.
   imAtt.SetColorKey(
      Color(0, 135, 0, 0),
      Color(255, 175, 255, 255),
      ColorAdjustTypePen);

   // Draw the image (metafile) using default and pen adjustment.
   // Colors drawn with a pen that have red components from 135 through 175
   // are transparent. Colors not drawn with a pen that have red components
   // from 80 to 120 are transparent.
   graphics.DrawImage(
      &image,
      Rect(0, 200, image.GetWidth(), image.GetHeight()),  // dest rect
      0, 0, image.GetWidth(), image.GetHeight(),          // source rect
      UnitPixel,
      &imAtt);

   // Clear the pen color key.
   imAtt.ClearColorKey(ColorAdjustTypePen);

   // Draw the image (metafile) using only default color adjustment.
   // No colors drawn with a pen are transparent. Colors not drawn with 
   // a pen that have red components from 80 to 120 are transparent.
   graphics.DrawImage(
      &image,
      Rect(0, 300, image.GetWidth(), image.GetHeight()),  // dest rect
      0, 0, image.GetWidth(), image.GetHeight(),          // source rect
      UnitPixel,
      &imAtt); 
}
				

이전 코드는 특정 파일과 함께 TestMetafile5.png 다음 출력을 생성했습니다. 왼쪽 열의 막대는 펜으로 그려졌으며 오른쪽 열의 막대는 브러시로 채워졌습니다. 기본 색 키는 브러시로 채워진 막대에 적용됩니다. 펜으로 그린 막대에 적용되는 색 키는 ImageAttributes::SetColorKeyImageAttributes::ClearColorKey 호출에 따라 달라집니다.

각각 두 개의 열로 구성된 4개 행의 막대를 보여 주는 일러스트레이션 마지막 두 행에는 각 행에 있는 서로 다른 수의 막대가 있습니다.

요구 사항

   
지원되는 최소 클라이언트 Windows XP, Windows 2000 Professional [데스크톱 앱만 해당]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 gdiplusimageattributes.h(Gdiplus.h 포함)
라이브러리 Gdiplus.lib
DLL Gdiplus.dll

참고 항목

Bitmap

색상

ColorAdjustType

이미지

ImageAttributes

ImageAttributes::ClearThreshold

ImageAttributes::SetColorKey

ImageAttributes::SetThreshold

Metafile

다시 칠하기