locked
Converting a JPG to BMP in GdiPlus RRS feed

  • Question

  • I'm trying to translate my 32-bit PB code for converting JPGs to BMP files to 64-bit C++ and it doesn't want to work.  It's not reporting any errors, just never gets past the Save->

    I put notes in the code below showing where it gets to and where it never gets to

    Any ideas?

    INT getencoderclsid(const WCHAR* format,CLSID* pClsid)
    {
         UINT  num = 0;          // number of image encoders
         UINT  size = 0;         // size of the image encoder array in bytes

         Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;
         Gdiplus::GetImageEncodersSize(&num, &size);

         if(size == 0)
           return -1;  // Failure

         pImageCodecInfo=(Gdiplus::ImageCodecInfo*)(malloc(size));

         if(pImageCodecInfo == NULL)
           return -1;  // Failure

         GetImageEncoders(num, size, pImageCodecInfo);

         for(UINT j = 0; j < num; ++j)
         {
           if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
           {
             *pClsid = pImageCodecInfo[j].Clsid;
             free(pImageCodecInfo);
             return j;  // Success
           }    
         }

         free(pImageCodecInfo);
         return -1;  // Failure
    }

    BOOL convertimage(std::string loadflname,std::string saveflname,std::string smimetype)
    {
         std::string b;
         std::wstring wtxt;
         BOOL retval;
         ULONG_PTR hgdiplus;
         Gdiplus::GdiplusStartupInput gpinput;
         Gdiplus::Image* lpimage;
         CLSID sencoderclsid;

         if((trim(loadflname) == "") || (trim(saveflname) == ""))
           return FALSE;

         // Initialize GDI+.
         gpinput.GdiplusVersion=1;
         Gdiplus::GdiplusStartup(&hgdiplus,&gpinput,NULL);

         if(left(smimetype,4) == "jpg/")
           smimetype="jpeg"+right(smimetype,(long)(smimetype.length()-3));

         if(right(smimetype,4) == "/jpg")
           smimetype=left(smimetype,(long)(smimetype.length()-3))+"jpeg";

         wtxt=strtowstr(smimetype);

         if(getencoderclsid(wtxt.c_str(),&sencoderclsid) == (-1))
         {  
           msgbox("Error "+str(GetLastError()));   
           return FALSE;
         }

         wtxt=strtowstr(loadflname);
         lpimage=Gdiplus::Image::FromFile(wtxt.c_str());

         wtxt=strtowstr(saveflname);

        //Got Here !!

         if(img->Save(wtxt.c_str(),&sencoderclsid,NULL) == Gdiplus::Status::Ok)
           retval=TRUE;
         else
           retval=FALSE;

         //never gets here !!

         delete lpimage;
         lpimage=0;
         Gdiplus::GdiplusShutdown(hgdiplus);

         return retval;
    }

    Tuesday, November 24, 2015 4:33 PM

Answers

  • Never mind - I solved my own problem... I accidentally used "img" instead of "lpimage" in the code above! LOL

    Sorry to bug you all.

    • Marked as answer by TallGuy63 Tuesday, November 24, 2015 4:38 PM
    Tuesday, November 24, 2015 4:38 PM

All replies

  • Never mind - I solved my own problem... I accidentally used "img" instead of "lpimage" in the code above! LOL

    Sorry to bug you all.

    • Marked as answer by TallGuy63 Tuesday, November 24, 2015 4:38 PM
    Tuesday, November 24, 2015 4:38 PM
  • Hi,

    Thanks for sharing solution with us.

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 25, 2015 2:44 AM