Thread: GDIPLUS::Image: how save it on a file in stream way?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> but these continues confused
    What are you confused about?

    gg

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    451
    Quote Originally Posted by Codeplug View Post
    >> 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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying Image from stream
    By NetCoder in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2013, 03:04 AM
  2. How can I save an image to file.
    By vmars316 in forum Windows Programming
    Replies: 1
    Last Post: 12-26-2010, 09:44 AM
  3. Low level program to save a mjpeg stream
    By Rufe0 in forum Linux Programming
    Replies: 6
    Last Post: 09-22-2009, 05:53 AM
  4. how to save one svg image by programing
    By sfguofen in forum C++ Programming
    Replies: 9
    Last Post: 09-04-2009, 08:11 PM
  5. How to get image from the screen and then save it to a file?
    By nomer in forum Windows Programming
    Replies: 2
    Last Post: 05-25-2006, 08:46 AM