Image::Save (constWCHAR*,constCLSID*,constEncoderParameters*) 方法 (gdiplusheaders.h)

Image::Save 方法會將此映射儲存至檔案。

語法

Status Save(
  const WCHAR             *filename,
  const CLSID             *clsidEncoder,
  const EncoderParameters *encoderParams
);

參數

filename

指定已儲存影像路徑名稱之 Null 終止字串的指標。

clsidEncoder

CLSID 的指標,指定要用來儲存影像的編碼器。

encoderParams

選擇性。 EncoderParameters 物件的指標,該物件會保存編碼器所使用的參數。 預設值是 NULL

傳回值

類型: 狀態

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

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

備註

GDI+ 不允許您將映像儲存到您用來建構映像的相同檔案。 下列程式代碼會將檔名MyImage.jpg傳遞至 Image 建構函式,以建立 Image 物件。 相同的檔名會傳遞至 Image 物件的 Image::Save 方法,因此 Image::Save 方法會失敗。

Image image(L"myImage.jpg");

// Do other operations.

// Save the image to the same file name. (This operation will fail.)
image.Save(L"myImage.jpg", ...);

範例

下列範例會從 PNG 檔案建立 Image 對象,然後根據該 Image 物件建立 Graphics 物件。 程序代碼會繪製影像、改變影像,然後再次繪製影像。 最後,程式代碼會將已改變的影像儲存至檔案。

程式代碼依賴 Helper 函式 GetEncoderClsid 來取得 PNG 編碼器的類別標識碼。 GetEncoderClsid 函式會顯示在擷取編碼器的類別標識碼中。

根據影像建構 Graphics 物件的技巧僅適用於特定影像格式。 例如,您無法根據每個圖元 4 位色彩深度的影像來建構 Graphics 物件。 如需 圖形 建構函式支援哪些格式的詳細資訊,請參閱 圖形

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

   // Create an Image object based on a PNG file.
   Image  image(L"Mosaic.png");

   // Draw the image.
   graphics.DrawImage(&image, 10, 10);

   // Construct a Graphics object based on the image.
   Graphics imageGraphics(&image);

   // Alter the image.
   SolidBrush brush(Color(255, 0, 0, 255));
   imageGraphics.FillEllipse(&brush, 20, 30, 80, 50);

   // Draw the altered image.
   graphics.DrawImage(&image, 200, 10);

   // Save the altered image.
   CLSID pngClsid;
   GetEncoderClsid(L"image/png", &pngClsid);
   image.Save(L"Mosaic2.png", &pngClsid, NULL);
}

規格需求

需求
標頭 gdiplusheaders.h

另請參閱

映像

EncoderParameter

EncoderParameters

GetImageEncoders

Image::Save 方法

Image::SaveAdd 方法

使用影像編碼器和譯碼器