•
•
•
•
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
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
c++ Syntax (Toggle Plain Text)
static Bool sys_ImageToFileJPEG (HBITMAP hImage, FILE* pFile) { Bool fRet = FALSE; if (hImage && pFile) { Gdiplus::Bitmap image ((HBITMAP)hImage, (HPALETTE)0); if (image.GetLastStatus() == Gdiplus::Ok) { CLSID encoderClsid; wimg_GetEncoderClsid (L"image/jpg", encoderClsid); // will not work - Save() wants an IStream!!! Gdiplus::Status hr = image.Save (pFile, &encoderClsid); if (Gdiplus::Ok == hr) { fRet = true; } } } return (fRet); }
•
•
Join Date: Dec 2006
Location: india
Posts: 1,085
Reputation:
Rep Power: 9
Solved Threads: 163
>> // will not work - Save() wants an IStream!!!
>> Gdiplus :: status hr = image.Save (pFile, &encoderClsid);
>> Gdiplus :: status hr = image.Save (pFile, &encoderClsid);
cplusplus Syntax (Toggle Plain Text)
// ...... IStream* pstm ; assert( CreateStreamOnHGlobal( 0, TRUE, &pstm ) >= 0 ) ; Gdiplus::Status hr = image.Save( pstm, &encoderClsid ) ; STATSTG stat ; assert( pstm->Stat( &stat, STATFLAG_NONAME ) >= 0 ) ; size_t sz = stat.cbSize.LowPart ; assert( stat.cbSize.HighPart == 0 ) ; HGLOBAL hg ; assert( GetHGlobalFromStream( pstm, &hg ) >= 0 ) ; assert( fwrite( GlobalLock(hg), sz, sz, pFile ) == sz ) ; GlobalUnlock(hg) ; pstm->Release() ; // .....
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- download pdf file, convert to html, in PHP since working in Linux (PHP)
- How to open txt file (Visual Basic 4 / 5 / 6)
- converting a text or xml file into binary format (Visual Basic 4 / 5 / 6)
- Starting With Java (Java)
- IStream to FILE * (C++)
- *.dat conversion to *.tax file pls help (C++)
- Convert any file type to pdf with distiller (C#)
- convert a file containing javascript to aspx (Community Introductions)
- Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!! (Java)
- VC++:convert File IStream to hex and store...? (C++)
Other Threads in the C++ Forum
- Previous Thread: C++ BGI Graphic Help!
- Next Thread: general question



Linear Mode