Image::Save 方法将此图像保存到流中。
语法
Status Save(
  [in] IStream                 *stream,
  [in] const CLSID             *clsidEncoder,
  [in] const EncoderParameters *encoderParams
);
参数
[in] stream
类型: IStream*
指向 IStream COM 接口的指针。 IStream 的实现必须包括 Seek、Read、Write 和 Stat 方法。
[in] clsidEncoder
类型: const CLSID*
指向 CLSID 的指针,该 CLSID 指定要用于保存图像的编码器。
[in] encoderParams
类型: const EncoderParameters*
可选。 指向包含编码器使用的参数的 EncoderParameters 对象的指针。 默认值为 NULL。
返回值
类型: 状态
如果方法成功,则返回 Ok,这是 Status 枚举的元素。
如果 方法失败,它将返回 Status 枚举的其他元素之一。
注解
不要将图像保存到用于构造映像的同一流中。 这样做可能会损坏流。
Image image(myStream); 
...
image.Save(myStream, ...); // Do not do this.
示例
以下示例创建两个 Image 对象:一个从 JPEG 文件构造,一个从 PNG 文件构造。 该代码创建一个包含两个流的复合文件,并将这两个图像保存到这些流中。
Status MakeCompoundFile()
{
   IStorage* pIStorage = NULL;
   IStream* pIStream1 = NULL;
   IStream* pIStream2 = NULL;
   HRESULT hr;
   Status stat = Ok;
   // Create two Image objects from existing files.
   Image image1(L"Crayons.jpg");
   Image image2(L"Mosaic.png");
   hr = CoInitialize(NULL);
   if(FAILED(hr))
      goto Exit;
   // Create a compound file object, and get
   // a pointer to its IStorage interface.
   hr = StgCreateDocfile(
      L"CompoundFile.cmp", 
      STGM_READWRITE|STGM_CREATE|STGM_SHARE_EXCLUSIVE, 
      0, 
      &pIStorage);
   if(FAILED(hr))
      goto Exit;
   // Create a stream in the compound file.
   hr = pIStorage->CreateStream(
      L"StreamImage1",
      STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
      0,
      0,
      &pIStream1);
   if(FAILED(hr))
      goto Exit;
   // Create a second stream in the compound file.
   hr = pIStorage->CreateStream(
      L"StreamImage2",
      STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
      0,
      0,
      &pIStream2);
   if(FAILED(hr))
      goto Exit;
   // Get the class identifier for the JPEG encoder.
   CLSID jpgClsid;
   GetEncoderClsid(L"image/jpeg", &jpgClsid);
   // Get the class identifier for the PNG encoder.
   CLSID pngClsid;
   GetEncoderClsid(L"image/png", &pngClsid);
   // Save image1 as a stream in the compound file.
   stat = image1.Save(pIStream1, &jpgClsid);
   if(stat != Ok)
      goto Exit;
   // Save image2 as a stream in the compound file.
   stat = image2.Save(pIStream2, &pngClsid);
Exit:
   if(pIStream1)
      pIStream1->Release(); 
   if(pIStream2)
      pIStream2->Release();
   if(pIStorage)
      pIStorage->Release();
   if(stat != Ok || FAILED(hr))
      return GenericError;
   return Ok;
}
要求
| 要求 | 值 | 
|---|---|
| 最低受支持的客户端 | Windows XP、Windows 2000 Professional [仅限桌面应用] | 
| 最低受支持的服务器 | Windows 2000 Server [仅限桌面应用] | 
| 目标平台 | Windows | 
| 标头 | gdiplusheaders.h (包括 Gdiplus.h) | 
| Library | Gdiplus.lib | 
| DLL | Gdiplus.dll |