次の方法で共有


Image.Save(IStream*, const CLSID*, const EncoderParameters*) method

Applies to: desktop apps only

The Image::Save method saves this image to a stream.

Syntax

Status Save(
  [in]  IStream *stream,
  [in]  const CLSID *clsidEncoder,
  [in]  const EncoderParameters *encoderParams
);

Parameters

  • stream [in]
    Type: IStream*

    Pointer to an IStream COM interface. The implementation of IStream must include the Seek, Read, Write, and Stat methods.

  • clsidEncoder [in]
    Type: const CLSID*

    Pointer to a CLSID that specifies the encoder to use to save the image.

  • encoderParams [in]
    Type: const EncoderParameters*

    Optional. Pointer to an EncoderParameters object that holds parameters used by the encoder. The default value is NULL.

Return value

Type:

Type: Status****

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Remarks

Do not save an image to the same stream that was used to construct the image. Doing so might damage the stream.

Image image(myStream); 
...
image.Save(myStream, ...); // Do not do this.

Examples

The following example creates two Image objects: one constructed from a JPEG file and one constructed from a PNG file. The code creates a compound file with two streams and saves the two images to those streams.

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;
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusheaders.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Image

EncoderParameter

EncoderParameters

GetImageEncoders

GetImageEncodersSize

Image::Save Methods

Image::SaveAdd Methods

Using Image Encoders and Decoders

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012