Solved

JPG -> BMP

Posted on 1998-08-18
7
1,315 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now