다음을 통해 공유


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

ImageAttributes::SetThreshold 메서드는 지정된 범주에 대한 임계값(투명도 범위)을 설정합니다.

구문

Status SetThreshold(
  [in]           REAL            threshold,
  [in, optional] ColorAdjustType type
);

매개 변수

[in] threshold

형식: REAL

임계값을 지정하는 REAL 숫자입니다.

[in, optional] type

형식: ColorAdjustType

색 임계값이 설정된 범주를 지정하는 ColorAdjustType 열거형의 요소입니다. 기본값은 ColorAdjustTypeDefault입니다.

반환 값

형식: 상태

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

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

설명

임계값은 각 색 구성 요소에 대한 컷오프 지점을 지정하는 0부터 1까지의 값입니다. 예를 들어 임계값이 0.7로 설정되어 있고 빨간색, 녹색 및 파란색 구성 요소가 230, 50 및 220인 색을 렌더링한다고 가정합니다. 빨간색 구성 요소(230)가 0.7×255보다 크므로 빨간색 구성 요소가 255(전체 강도)로 변경됩니다. 녹색 구성 요소(50)는 0.7×255 미만이므로 녹색 구성 요소는 0으로 변경됩니다. 파란색 구성 요소(220)가 0.7×255보다 크므로 파란색 구성 요소가 255로 변경됩니다.

ImageAttributes 개체는 기본, 비트맵, 브러시, 펜 및 텍스트의 다섯 가지 조정 범주에 대한 색 및 회색조 설정을 유지 관리합니다. 예를 들어 기본 범주에 대한 임계값, 비트맵 범주에 대한 임계값 및 펜 범주에 대해 여전히 다른 임계값을 지정할 수 있습니다.

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

특정 범주에 대해 색 또는 회색조 조정 설정을 지정하는 즉시 기본 조정 설정이 해당 범주에 더 이상 적용되지 않습니다. 예를 들어 기본 범주에 대한 조정 설정 컬렉션을 지정한다고 가정합니다. ColorAdjustTypePenImageAttributes::SetThreshold 메서드에 전달하여 펜 범주에 대한 임계값을 설정하는 경우 펜에 기본 조정 설정이 적용되지 않습니다.

예제

다음 예제에서는 .bmp 파일을 기반으로 Image 개체를 만듭니다. 또한 이 코드는 ImageAttributes 개체를 만들고 비트맵 임계값을 0.6으로 설정합니다. 그런 다음, 코드는 이미지를 두 번 그립니다. 한 번은 색 조정 없이, 한 번은 임계값으로 지정된 조정으로 그립니다.


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

   // Create an Image object based on a .bmp file.
   // The image has one stripe with RGB components (160, 0, 0)
   // and one stripe with RGB components (0, 140, 0).
   Image image(L"RedGreenThreshold.bmp");

   // Create an ImageAttributes object, and set its bitmap threshold to 0.6.
   ImageAttributes imAtt;
   imAtt.SetThreshold(0.6f, ColorAdjustTypeBitmap);

   // Draw the image with no color adjustment.
   graphics.DrawImage(&image, 10, 10, image.GetWidth(), image.GetHeight());
 
   // Draw the image with the threshold applied.
   // 160 > 0.6*255, so the red stripe will be changed to full intensity.
   // 140 < 0.6*255, so the green stripe will be changed to zero intensity.   
   graphics.DrawImage(&image,
      Rect(100, 10, image.GetWidth(), image.GetHeight()),  // dest rect
      0, 0, image.GetWidth(), image.GetHeight(),           // source rect
      UnitPixel,
      &imAtt);
}
				

다음 그림에서는 이전 코드의 출력을 보여 줍니다. 빨간색은 최대 강도로 변환되었고 녹색은 0 강도로 변환되었습니다.

적갈색 및 녹색 영역이 있는 사각형을 보여 주는 그림, 동일한 사각형을 보여 주지만 빨간색과 검은색으로 렌더링됨

요구 사항

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

참고 항목

Bitmap

색상

ColorAdjustType

이미지

ImageAttributes

ImageAttributes::ClearColorKey

ImageAttributes::ClearThreshold

ImageAttributes::SetColorKey

Metafile

다시 칠하기