[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now



Posted on 1998-08-18
Medium Priority
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 ?

Question by:WxW
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2

Expert Comment

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


Expert Comment

ID: 1413624
At this internet address:

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)

Author Comment

ID: 1413625
I will process both options to see which is best and faster .
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.


Author Comment

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

Expert Comment

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

Accepted Solution

snoegler earned 60 total points
ID: 1413628
Thanks :)

Author Comment

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 ....


Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

656 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