Image::Save(IStream*,constCLSID*,constEncoderParameters*) method (gdiplusheaders.h)
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
[in] stream
Type: IStream*
Pointer to an IStream COM interface. The implementation of IStream must include the Seek, Read, Write, and Stat methods.
[in] clsidEncoder
Type: const CLSID*
Pointer to a CLSID that specifies the encoder to use to save the image.
[in] encoderParams
Type: const EncoderParameters*
Optional. Pointer to an EncoderParameters object that holds parameters used by the encoder. The default value is NULL.
Return value
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
Requirement | Value |
---|---|
Minimum supported client | Windows XP, Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | gdiplusheaders.h (include Gdiplus.h) |
Library | Gdiplus.lib |
DLL | Gdiplus.dll |