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

傳回值

類型: 狀態

如果方法成功,它會傳回 Ok,這是 Status 列舉的元素。

如果方法失敗,它會傳回 Status 列舉的其中一個其他元素。

備註

臨界值是從 0 到 1 的值,指定每個色彩元件的截止點。 例如,假設閾值設定為 0.7,假設您呈現的色彩是紅色、綠色和藍色元件為 230、50 和 220。 紅色元件 230 大於 0.7×255,因此紅色元件會變更為 255 (完整濃度) 。 綠色元件 50 小於 0.7×255,因此綠色元件會變更為 0。 藍色元件 220 大於 0.7×255,因此藍色元件會變更為 255。

ImageAttributes物件會維護五個調整類別的色彩和灰階設定:預設、點陣圖、筆刷、手寫筆和文字。 例如,您可以指定預設類別的臨界值、點陣圖類別的臨界值,以及畫筆類別的臨界值仍然不同。

預設色彩和灰階調整設定會套用至沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。

一旦您指定特定類別的色彩或灰階調整設定,預設調整設定就不再套用至該類別。 例如,假設您指定預設類別的調整設定集合。 如果您藉由將 ColorAdjustTypePen 傳遞至 ImageAttributes::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);
}
				

下圖顯示上述程式碼的輸出。 請注意,紅色已轉換成最大濃度,而綠色已轉換為零濃度。

圖例顯示具有紅色和綠色區域的矩形,然後以紅色和黑色呈現的相同矩形

需求

   
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平台 Windows
標頭 gdiplusimageattributes.h (include Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

點陣圖

Color

ColorAdjustType

映像

ImageAttributes

ImageAttributes::ClearColorKey

ImageAttributes::ClearThreshold

ImageAttributes::SetColorKey

中繼檔

重新著色