Win7 (Ultimate version), OleLoadPicture load in-memory picture (MAGICKGETIMAGEBLOB), return value < 0

Source: Internet
Author: User

Yesterday to three elder brother, want to take a picture to narrow down, I wrote a long time ago a software to zoom out, and then a preview of the effect, this time pop-up:

Call OleLoadPicture FAIL-LOADPICTUREFROMMW

Strange, this picture batch processing software I have been in use, in the XP system has never appeared such a hint, why in the Win7 under the normal picture effect preview?

What I can not accept is that there has never been a user or friend to me to respond to this problem, they do not have to Win7?

This afternoon asked a friend borrowed a Win7 notebook, through an afternoon test, solve the problem.

Before the code idea:

Get a picture of the pointer and length in memory by Pbyte pData =magickgetimageblob (Magickwand *, size_t length).

if (CreateStreamOnHGlobal (PData, FALSE, &pstream) = = S_OK)//Convert byte array to istream* {if (SUCCEEDED (oleloadpict Ure (pstream, Length, TRUE, &iid_ipicture, (void**) &ppic)))

This code runs all normal under XP, can load the picture data that pData points to normally.

But under Win7 's flagship edition, OleLoadPicture (...) return value < 0

I haven't found a solution for 2 hours, and this time I think of oleloadpicture when loading a file, allocate a memory space based on the file size, and then load the file into the specified memory space:

handle filehandle;    ulong sizeh, sizel, readcount;     IStream *pstream = NULL;    //IPicture *pPic = NULL;        filehandle = createfile (pFilePath,                              GENERIC_READ,                              file_share_read,                             NULL,                              open_existing,                             file_attribute_normal,  NULL                            );        if (filehandle == invalid_handle_value)         return;        sizel = getfilesize (Filehandle, &sizeh);        hglobal pbuffer = globalalloc (Gmem_moveable, sizel);        if (pbuffer == null)     {         closehandle (FileHandle);        return;     }&nbsP;      lpvoid pdes = globallock (PBuffer);        if (ReadFile (filehandle, pdes, sizel, &readcount, null)  ==  0)     {        globalunlock (pBuffer);         closehandle (FileHandle);            globalfree (pbuffer);  //Release Global Memory             return;    }       globalunlock ( pbuffer);     closehandle (FileHandle);        if ( CreateStreamOnHGlobal (Pbuffer, true, &pstream) &NBSP;!=&NBSP;S_OK)     {         globalfree (pbuffer);  //Release Global Memory          return;  &nBsp; }       if (SUCCEEDED (OleLoadPicture (pstream, SizeL,  true, &iid_ipicture,  (void**) &ppic))     {

Since pdata is the picture data pointer obtained through MAGICKGETIMAGEBLOB (), could oleloadpicture not be able to load the image data pointing to pdata?

I'll just follow the way oleloadpicture loads the picture file, allocate a memory space based on the image size (length), and then use memcpy to copy the data that points to pdata to pbuffer, then use OleLoadPicture to load Pbuffer picture data, this solves the problem under the Win7:

Size_t length;    pbyte pdata = magickgetimageblob (mw, & length);  //reads the complete byte array from the MW       //printf ("length:%d\n", length);       //Test found in  [windows 7 flagship edition], createstreamonhglobal &  oleloadpicture  cannot directly use  pdata,    //after various attempts, it is found that you can request a temporary memory space (pbuffer),  will  PData  copy one to this memory space: pbuffer    //then use  CreateStreamOnHGlobal &  oleloadpicture  handling  pBuffer  instead of  PData      HGLOBAL  Pbuffer = globalalloc (gmem_moveable, length);  //opens up a memory space     lpvoid  pdes = globallock (pbuffer);  //Lock Memory Space     memcpy (pDes,pData,length);  //Copy the contents of  pData  to  pbuffer    globalunlock (pbuffer);  //Unlock memory space       istream&nbsP;*pstream = null;      if (CreateStreamOnHGlobal (PBuffer, FALSE,  &pstream) &NBSP;==&NBSP;S_OK)  //convert byte array to  IStream*    {         if (SUCCEEDED (OleLoadPicture (pstream, length, true, &iid _ipicture,  (void**) &ppic)))



2013-06-03

Win7 (Ultimate version), OleLoadPicture load in-memory picture (MAGICKGETIMAGEBLOB), return value < 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.