Bitmap::SetPixel 方法 (gdiplusheaders.h)

Bitmap::SetPixel 方法會設定此點陣圖中指定圖元的色彩。

語法

Status SetPixel(
  [in]      INT           x,
  [in]      INT           y,
  [in, ref] const Color & color
);

參數

[in] x

類型: INT

int ,指定圖元的 x 座標 (資料行) 。

[in] y

類型: INT

int ,指定圖元的 Y 座標 (列) 。

[in, ref] color

類型: const Color

指定要設定之色彩的 Color 物件的參考。

傳回值

類型: 狀態

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

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

備註

根據位圖的格式, Bitmap::GetPixel 可能不會傳回 與 Bitmap::SetPixel 設定相同的值。 例如,如果您在圖元格式為 32bppPARGB 的 Bitmap 物件上呼叫 Bitmap::SetPixel,則 RGB 元件會預先乘以。 後續呼叫 Bitmap::GetPixel 可能會因為捨入而傳回不同的值。 此外,如果您在色彩深度為每個圖元 16 位的點陣圖上呼叫 Bitmap::SetPixel,則從 32 到 16 位的轉換中可能會遺失資訊,而後續呼叫 Bitmap::GetPixel 可能會傳回不同的值。

範例

下列範例會根據 JPEG 檔案建立 Bitmap 物件。 程序代碼會在未變更之後繪製位圖。 然後程式代碼會呼叫 Bitmap::SetPixel 方法,以在點陣圖中建立黑色圖元的核取模式,並繪製改變的位陣圖。

VOID Example_SetPixel(HDC hdc)

{
   Graphics graphics(hdc);

   // Create a Bitmap object from a JPEG file.
   Bitmap myBitmap(L"Climber.jpg");

   // Draw the bitmap.
   graphics.DrawImage(&myBitmap, 0, 0);

   // Create a checkered pattern with black pixels.
   for (UINT row = 0; row < myBitmap.GetWidth(); row += 2)
   {
      for (UINT col = 0; col < myBitmap.GetHeight(); col += 2)
      {
         myBitmap.SetPixel(row, col, Color(255, 0, 0, 0));
      }
   }

   // Draw the altered bitmap.
   graphics.DrawImage(&myBitmap, 200, 0);
}

規格需求

需求
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限桌面應用程式]
最低支援的伺服器 Windows 2000 Server [僅限桌面應用程式]
目標平台 Windows
標頭 gdiplusheaders.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

點陣圖

Bitmap::GetPixel

色彩

映像

影像、點陣圖和中繼檔

使用影像、位圖和元檔