Solved

JPG -> BMP

Posted on 1998-08-18
7
1,324 Views
Last Modified: 2013-12-03
I have my app to load some BMP's from resources . The problem is that BMP's are really large .. and my EXE is > 3MB . I wonder how could I load JPG and convert it to a HBITMAP or something .. Can anyone help me ?

Thanks
0
Comment
Question by:WxW
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1413623
You can, but you have to write some code

Insert file as custom resource into your app, for VC5 do it like this
1. Insert Menu, click Resource...
2. click Import... on the dialog.  
3. Browse the filename and press Import button
4. For resource type type a string e.g. "JPEG" (without the quotes)
If you do this write you get a custom resource called something like IDR_JPEG1 which when you open it up you get a tonne of hex (hex dump of the file)

Now coding
1. Get an HRSRC resource handle using FindResource or FindResourceHandleEx
2. Call LoadResource using the HRSRC to get an HGLOBAL which is the handle to a block of global memory containg the data.
3. Assuming you got this far, GlobalLock to get a pointer to the data
4. Decompress the JPEG into memory (see below)
5. GlobalUnlock the HGLOBAL
Be sure to put error checking in through out, as most of the opps can go wrong if out of memory of called with bad params

To decompress this JPEG into an HBITMAP you need to write code to do this.  Most code I've seen does this files rather than memory.  
You can either adapt this from scratch, or if starting MFC based code override CFile to work on memory (or use CMemFile and Attach it to the RAM)

One site with JPEG code is (haven't tried this one)
http://www.cs.tu-berlin.de/~uzadow/paintlib/index.html (check for BITMAP.ZIP near the bottom of the page)

Otherwise you can get the necessary code from Stingray (Objective Toolkit) or Periphere (Weekly MFC) if you don't want to live with the above's licensing rules





0
 
LVL 6

Expert Comment

by:snoegler
ID: 1413624
At this internet address:
http://einstein.ae.eng.ua.edu/nishita/index.htm 

you can get the freely distributable freeware 'nviewlib.dll' which contains a really simple
API to load multiple file formats(jpg,gif, ...). Try it, i've been using it in a semi-commercial
(in-house) application, and i got no problems yet (about 3/4 year long)
0
 
LVL 6

Author Comment

by:WxW
ID: 1413625
I will process both options to see which is best and faster .
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 6

Author Comment

by:WxW
ID: 1413626
I found the dll & lib more effective and useful , please snoegler answer . Answer2000 thanks anyway :)
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1413627
Well I didn't know about that.  Programming's always better if you can somebody else to write the code for you :-)
0
 
LVL 6

Accepted Solution

by:
snoegler earned 20 total points
ID: 1413628
Thanks :)
0
 
LVL 6

Author Comment

by:WxW
ID: 1413629
Thanks snoegler also .
Answer2000 : I agree that writing your own code is much much much much more effective and you are "proud" of it . But lemme tell you that my first decision to start such a heavy app with plain C++ and API ( not using MFC or most OWL libraries ) , has allready filled 50000 lines of code and I might need more 50000 . I am a little tired , so I prefer not doing things that others have ready for me ....

Cya
Michael
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question