code_ninja Posted July 29, 2009 Share Posted July 29, 2009 Do any of you have a (working) .jpg to .bmp converter? I'm working on a setbackground type script app that loads random backgrounds from my pc. I already got it to load BMP's. But It won't load JPEG's. I would prefer it if you provided the source code. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/ Share on other sites More sharing options...
0 code_ninja Posted July 29, 2009 Author Share Posted July 29, 2009 bump Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591351702 Share on other sites More sharing options...
0 azcodemonkey Posted July 29, 2009 Share Posted July 29, 2009 (edited) grrr it was bmp to jpeg I take it you're trying to do this on Windows? Edited July 29, 2009 by azcodemonkey Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591351766 Share on other sites More sharing options...
0 azcodemonkey Posted July 29, 2009 Share Posted July 29, 2009 Just in case you're doing it on Windows, here's an example of converting a jpeg to bmp: #include <windows.h> #include <gdiplus.h> #define WINDOWS_LEAN_AND_MEAN using namespace Gdiplus; 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 ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; // Failure pImageCodecInfo = (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; } int main(void){ GdiplusStartupInput startupInput; ULONG_PTR token; GdiplusStartup(&token, &startupInput, NULL); Image testImg(L"c:\\test.jpg", false); CLSID clsid; int ret = -1; if(-1 != GetEncoderClsid(L"image/bmp", &clsid)){ ret = testImg.Save(L"c:\\test.bmp", &clsid); } GdiplusShutdown(token); return ret; } Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591352030 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 (edited) Oh, yeah. I need it to be cross-platform. Looking for a function like: int JpegToBmp(char* jfile, char* bfile){ //code here //jpeg output to bfile return bfile; } int main(){ JpegToBmp("C:\\1.jpg","C:\\1.bmp"); } Thanks Edited July 30, 2009 by dramonai Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591352732 Share on other sites More sharing options...
0 code.kliu.org Posted July 30, 2009 Share Posted July 30, 2009 BMP is a Windows (and OS/2) format. The HBITMAP handle is very much a Windows-specific thing. Why do you want this to be cross-platform? And you do realize that, even for .bmp files, there are many different types of bitmaps, right? So... um, are you really sure you need/want this to be cross-platform? Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591352856 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 I would prefer not to use the Gdiplus namespace. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353368 Share on other sites More sharing options...
0 code.kliu.org Posted July 30, 2009 Share Posted July 30, 2009 I would prefer not to use the Gdiplus namespace. That's a really bad reason to reject this approach. First, you don't have to use that namespace. Or, you can squirrel all this away in a separate source file. Etc. The alternative is to roll your own implementation (or copy some existing implementation), which is wasteful if you can avoid it by using a system library like GdiPlus or WIC (Vista or later). Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353416 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 Gdiplus doesn't even work on my machine. I don't have the header files and libraries with my compiler(mingw32-gcc). I've tried CxImage,ipl98,DevIL, and a bunch of other Image Processing Libraries and none of them worked (probably because they were coded with MS VC++ 6, and I'm using mingw) BTW I want to convert a 24-bit JPG to a 24-bit bitmap (another thing) I already tried using a command-line image converter via system() but it didn't work. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353424 Share on other sites More sharing options...
0 Mike Posted July 30, 2009 Share Posted July 30, 2009 DevIL should work fine what you want to do and afaik it's cross-platform, what specific issues did you come across? Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353444 Share on other sites More sharing options...
0 code.kliu.org Posted July 30, 2009 Share Posted July 30, 2009 So it's not cross-platform you're after, it's cross-compiler... If you're developing on Windows, you are going to need the Windows SDK no matter what compiler you use. And as a bonus, the SDK also contains a free copy of MSFT's own compiler that you can use (though mingw-gcc should work for GDI+). GDI+ actually uses a regular, flat C API (which is definitely cross-compiler-safe), that is then wrapped in a bunch of C++ classes via the headers (which you get through the SDK) so that C++ users can pretend that GDI+ is C++. As a last resort, you can always just bypass the middleman and use GDI+ as any old set of flat C APIs. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353446 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 (edited) So it's not cross-platform you're after, it's cross-compiler... Well, actually it is cross-platform because unix/macosx have gcc. Downloading SDK... EDIT:(OMG this will take a while...) Edited July 30, 2009 by dramonai Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353464 Share on other sites More sharing options...
0 Karl L. Posted July 30, 2009 Share Posted July 30, 2009 Funny, I was about to suggest CxImage, after my pleasant experience with it in a recent project. It compiles fine for me on both MinGW 3.4.5 (stable) and MinGW 4.4.0 (testing) (with the latest Win32API, of course.) I had to make some slight modifications, though, to get it to compile with libJPEG and libPNG. It should work like a charm for what you need. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353502 Share on other sites More sharing options...
0 code.kliu.org Posted July 30, 2009 Share Posted July 30, 2009 Well, actually it is cross-platform because unix/macosx have gcc. If you intend to have your program run on *nix without Wine, then it's cross-platform, and you probably shouldn't use GDI+ (you still can, if you find an alternative method for your *nix builds) (note that BMP files are used much outside of Windows). If you intend your program to run only on Windows, then it's cross-compiler (even if the compiler can compile for other platforms). Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353510 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 Funny, I was about to suggest CxImage, after my pleasant experience with it in a recent project. It compiles fine for me on both MinGW 3.4.5 (stable) and MinGW 4.4.0 (testing) (with the latest Win32API, of course.) I had to make some slight modifications, though, to get it to compile with libJPEG and libPNG. It should work like a charm for what you need. Do you think you could send me a CxImage Makefile? Or tell me how to compile it. Before I couldn't get it to compile. If you intend to have your program run on *nix without Wine, then it's cross-platform, and you probably shouldn't use GDI+ (you still can, if you find an alternative method for your *nix builds) (note that BMP files are used much outside of Windows). If you intend your program to run only on Windows, then it's cross-compiler (even if the compiler can compile for other platforms). Well, I'm developing this for both Ubuntu and Windows, maybe even Mac so... Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353534 Share on other sites More sharing options...
0 azcodemonkey Posted July 30, 2009 Share Posted July 30, 2009 If you're serious about cross-platform, use QT. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353550 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 If you're serious about cross-platform, use QT. Me no like qt. The framework is way too freakin large. To run my program, the downloader would have to download 100MB+ of DLL's. Plus, right now I'm just working on the console with file handling, and the like. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353562 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 I still can't get anything to work. Help? Anyone? Load JPEG from file, save as bitmap. not working :angry: argh... Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353726 Share on other sites More sharing options...
0 code_ninja Posted July 30, 2009 Author Share Posted July 30, 2009 Giving up... :( Don't really need to convert. I'll just convert the jpeg's manually then add the path's to the bmp's to my ini file. Thanks to everyone who helped. Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591353740 Share on other sites More sharing options...
0 Patrick333 Posted August 6, 2009 Share Posted August 6, 2009 Just in case you're doing it on Windows, here's an example of converting a jpeg to bmp: Useless code. You can do it with 1 api call on Windows (Shell)... Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591389736 Share on other sites More sharing options...
0 azcodemonkey Posted August 6, 2009 Share Posted August 6, 2009 Useless code.You can do it with 1 api call on Windows (Shell)... So... Instead of you being an arrogant **** head, why not post the code and enlighten us? Jeezus, now I remember why I stopped posting here. I mostly code for the web these days, so forgive my ignorance of the shell that I haven't even looked at in years, O Mighty One! Link to comment https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/#findComment-591390868 Share on other sites More sharing options...
Question
code_ninja
Do any of you have a (working) .jpg to .bmp converter?
I'm working on a setbackground type script app that loads random backgrounds from my pc.
I already got it to load BMP's. But It won't load JPEG's.
I would prefer it if you provided the source code.
Link to comment
https://www.neowin.net/forum/topic/803984-cc-jpg-to-bmp-conversion/Share on other sites
20 answers to this question
Recommended Posts