finally i can get the actual\1st frame... but i need all frames(animated gif):
Code:
friend std::ostream& operator << (std::ostream& lhs, image& rhs)
{
//Create an empty IStream:
IStream* pIStream = nullptr;
if(CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pIStream)!=S_OK)
DebugText("error on creating an empty IStream");
//choose image format for save it on IStream:
// Get encoder class id for jpg compression
// for other compressions use
// image/bmp
// image/jpeg
// image/gif
// image/tiff
// image/png
CLSID pngClsid;
GetEncoderClsid(L"image/tiff", &pngClsid);
// Setup encoder parameters
EncoderParameters *encoderParameters=(EncoderParameters*)malloc(sizeof(EncoderParameters));
encoderParameters->Count = 1;
encoderParameters->Parameter[0].Guid = EncoderSaveFlag;
encoderParameters->Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParameters->Parameter[0].NumberOfValues = 1;
// setup compression level
ULONG parameterValue = 50;
encoderParameters->Parameter[0].Value = ¶meterValue;
// Save the 1st frame to the stream
parameterValue = EncoderValueMultiFrame;
Status stat;
if(rhs.img->Save(pIStream, &pngClsid, encoderParameters) != Ok)
{
pIStream->Release();
MessageBox("error on saving to IStream");
}
//stop the animation:
rhs.tmrAnimation.Stop();
//save all frame on stream:
for(int i=1; i<rhs.framecount; i++)
{
//select the frame for be saved:
UINT count = 0;
count = rhs.img->GetFrameDimensionsCount();
vector<GUID> pDimensionIDs;
pDimensionIDs.resize(count);
rhs.img->GetFrameDimensionsList(pDimensionIDs.data(), pDimensionIDs.size());
rhs.img->SelectActiveFrame(&pDimensionIDs[0],i);
//save the frame on stream:
parameterValue = EncoderValueFrameDimensionPage;
stat=rhs.img->Save(pIStream,&pngClsid, encoderParameters);
//select the actual frame for the timer animation:
if(i==rhs.framecount-1)
rhs.img->SelectActiveFrame(&pDimensionIDs[0],rhs.intSelectFrame);
//testing if was saved:
if(stat == Ok)
DebugText("Page " + to_string(i) + " saved successfully.");
else
DebugText("Page " + to_string(i) + " not saved successfully.\t" + to_string(stat));
}
//closing stream:
parameterValue = EncoderValueFlush;
stat=rhs.img->SaveAdd(encoderParameters);
if(stat != Ok)
DebugText("Page not saved successfully: " + to_string(GetLastError()) + " " + to_string(stat) );
//continue the timer:
if(rhs.framecount>0)
rhs.tmrAnimation.Start();
//getting the stream size:
STATSTG sts;
pIStream->Stat(&sts, STATFLAG_DEFAULT);
ULARGE_INTEGER uli = sts.cbSize;
LARGE_INTEGER zero;
zero.QuadPart = 0;
int size = (int)uli.QuadPart;
//save the stream to char*
char* bits = new char[size];
DebugText("write: " + to_string(size));
ULONG written;
pIStream->Seek(zero, STREAM_SEEK_SET, NULL);
pIStream->Read(bits, size, &written);
//write the stream size on file
lhs.write(reinterpret_cast<char*>(&size),sizeof(int));
//write pBuff data on file
lhs.write(reinterpret_cast<char*>(bits),size);
//clean resources
delete[] bits;
pIStream->Release();
free(encoderParameters);
return lhs;
}
see the 'for' give me a positive output, so the frame seems to be saved on stream.
but when i need close the stream:
Code:
//closing stream:
parameterValue = EncoderValueFlush;
stat=rhs.img->SaveAdd(encoderParameters);
if(stat != Ok)
DebugText("Page not saved successfully: " + to_string(GetLastError()) + " " + to_string(stat) );
- the GetLastError() give me zero;
- the stat give me 7. so it's a win32 error(from stat enum).
what i'm doing wrong for save all frames on stream?