Originally Posted by
Codeplug
>> but these continues confused
What are you confused about?
gg
you(both) told me for i do in these way:
(for save it on file)
1 - create an empty IStream:
Code:
IStream* pIStream = nullptr;
HGLOBAL hg=NULL;
if(CreateStreamOnHGlobal(hg, FALSE, (LPSTREAM*)&pIStream)!=S_OK)
2 - save the Image to IStream:
Code:
CLSID pngClsid;
GetEncoderClsid(L"image/gif", &pngClsid);
// Setup encoder parameters
EncoderParameters encoderParameters;
encoderParameters.Count = 1;
encoderParameters.Parameter[0].Guid = EncoderQuality;
encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParameters.Parameter[0].NumberOfValues = 1;
// setup compression level
ULONG quality = 50;
encoderParameters.Parameter[0].Value = &quality;
// Save the image to the stream
if(rhs.img->Save(pIStream, &pngClsid, &encoderParameters) != Ok)
3 - getting IStream size:
Code:
int buffsize=GlobalSize(&hg);
4 - i must save the IStream on a buffer:
Code:
char *pBuff = new char[buffsize];
ULONG ulBytesRead;
//Read the stream to pBuff
if(pIStream->Read(pBuff,buffsize, &ulBytesRead)!=S_OK)
5 -now save the buffer size on file and the buffer:
Code:
//write the stream size on file
lhs << buffsize;
//write pBuff data on file
lhs << pBuff;
6 - we must delete the resources:
Code:
//clean resources
delete[] pBuff;
pIStream->Release();
PS: i know the file it's created, what i don't have sure if the data it's right on file.
now for read it from a file:
1 - create an empty IStream:
Code:
IStream* pIStream = nullptr;
HGLOBAL hg=NULL;
if(CreateStreamOnHGlobal(hg, FALSE, (LPSTREAM*)&pIStream)!=S_OK)
2 - read the buffer(inclued the buffer size) from the file to a new IStream:
Code:
/getting IStream size:
int streamsize;
lhs.read(reinterpret_cast<char*>(&streamsize), sizeof(streamsize));
IStream* pIStream = nullptr;
// Create stream with 0 size
HGLOBAL hg= ::GlobalAlloc(GMEM_MOVEABLE,streamsize);
GlobalLock(hg);
lhs.read(reinterpret_cast<char*>(&hg),sizeof(streamsize));
GlobalUnlock(hg);
if(CreateStreamOnHGlobal(&hg, TRUE, (LPSTREAM*)&pIStream)!=S_OK)
DebugText("error on creating an empty IStream");
(i don't get any error)
3 - reading IStream to Image class:
Code:
if(rhs.img->FromStream(pIStream,TRUE)!=S_OK)
DebugText("error reading stream to Image");
4 - clean resources:
Code:
//realease resources:
pIStream->Release();
GlobalFree(hg);
i see what i must do(unless i miss something). but if the FromStream() give me an error, means the IStream isn't right. i don't understand why.. i'm totaly confused.
sorry to all, but i'm trying to understand and see what isn't right