User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,595 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,417 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1406 | Replies: 2
Reply
Join Date: Sep 2007
Posts: 2
Reputation: dbgarlisch is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dbgarlisch dbgarlisch is offline Offline
Newbie Poster

How do I convert a FILE* to an IStream

  #1  
Sep 7th, 2007
How do I convert a FILE* to an IStream!

Using GDI+, I want to save an HBITMAP to a disk file as JPG.

However, I am doing this within a legacy function that provides an already opened FILE* as a parameter.

I have found nothing in the docs.

  1. static Bool sys_ImageToFileJPEG (HBITMAP hImage, FILE* pFile)
  2. {
  3. Bool fRet = FALSE;
  4.  
  5. if (hImage && pFile)
  6. {
  7. Gdiplus::Bitmap image ((HBITMAP)hImage, (HPALETTE)0);
  8.  
  9. if (image.GetLastStatus() == Gdiplus::Ok)
  10. {
  11. CLSID encoderClsid;
  12.  
  13. wimg_GetEncoderClsid (L"image/jpg", encoderClsid);
  14.  
  15. // will not work - Save() wants an IStream!!!
  16. Gdiplus::Status hr = image.Save (pFile, &encoderClsid);
  17.  
  18. if (Gdiplus::Ok == hr)
  19. {
  20. fRet = true;
  21. }
  22. }
  23. }
  24.  
  25. return (fRet);
  26. }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,085
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Rep Power: 9
Solved Threads: 163
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: How do I convert a FILE* to an IStream

  #2  
Sep 8th, 2007
>> // will not work - Save() wants an IStream!!!
>> Gdiplus :: status hr = image.Save (pFile, &encoderClsid);

  1. // ......
  2. IStream* pstm ; assert( CreateStreamOnHGlobal( 0, TRUE, &pstm ) >= 0 ) ;
  3. Gdiplus::Status hr = image.Save( pstm, &encoderClsid ) ;
  4. STATSTG stat ; assert( pstm->Stat( &stat, STATFLAG_NONAME ) >= 0 ) ;
  5. size_t sz = stat.cbSize.LowPart ; assert( stat.cbSize.HighPart == 0 ) ;
  6. HGLOBAL hg ; assert( GetHGlobalFromStream( pstm, &hg ) >= 0 ) ;
  7. assert( fwrite( GlobalLock(hg), sz, sz, pFile ) == sz ) ;
  8. GlobalUnlock(hg) ; pstm->Release() ;
  9. // .....
Reply With Quote  
Join Date: Sep 2007
Posts: 2
Reputation: dbgarlisch is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dbgarlisch dbgarlisch is offline Offline
Newbie Poster

Re: How do I convert a FILE* to an IStream

  #3  
Sep 11th, 2007
Thanks! I will give this a try.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC