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

x
?
Solved

I need a source code - how to use JPG-images in Visual C++?

Posted on 2001-06-11
15
Medium Priority
?
621 Views
Last Modified: 2013-11-19
Hello everybody!

Can you provide me with a source code - which is able to operate with JPEG-images using C++ and Win32API? (I mean without MFC or any other HUGE libraries) Also it should works on Windows 95, NT 4.0 and greater. I don't need to save images, only to load them from files and dislay them on the screen.

I wrote a small game. The .exe file size is 32Kb.
But using .bmp files means to inflate the game size.
F.e. the file size of all images in .bmp = 115Kb but in JPEG = 64Kb. Do you see the difference? Plus JPEG images looks better.
If you also provide me with a some good website about game programming technics in C++ it would be perfect and will costs more points! :)

Thank you in advance!
0
Comment
Question by:Masonok
[X]
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
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6176511
Why not get a copy of the IJG Jpeg Library source www.ijg.org
This can easily be compiled into a very small standallone lib file for you to use.

Alternatively you could use the windows OleLoadPicture() function (search MSDN for LoadPic for an example).

Note the second solution uses OLE dlls which are not present on a clean installation of the original Win95.
0
 

Author Comment

by:Masonok
ID: 6176616
From MSDN
<B>Remarks</B>
The stream must be in BMP (bitmap), WMF (metafile), or ICO (icon) format... ? It doesn't mention about JPG.


0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6176862
Of couse http://www.ijg.org
supports jpg file: it is
Independedny JPEG groupe.
Other places for code:
http://www.vsce.com/src_code/faq_source_code.html
Or PaintLib -> may be some URL's,every time migrates:
www.paintlib.de 
www.paintlib.com
home.wxs.nl/~flvdberg
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Expert Comment

by:qocarlos
ID: 6178878
Masonok,

OleLoadPicturePath it does support jpeg files. I have written a couple of applications that loads and display JPEG files using this function and it works correctly.

Carlos

0
 

Expert Comment

by:NickAtBOM
ID: 6180569
IPictureDisp* p1;

CComBSTR str(_T("C:\\Image.jpg"));

HRESULT hr = OleLoadPicturePath(str,     // path to load                    NULL,  // IUnknown for aggregation               NULL,  // reserved                         NULL,                              IID_IPictureDisp,                         (void**)&p1);
0
 

Accepted Solution

by:
NickAtBOM earned 600 total points
ID: 6180593
Pressing the 'tab' key is not a good idea (see my last answer)

What I meant to say is....


The best way to quickly load jpegs is to use OleLoadPicturePath win32 api function.  This creates an OLE picture object and returns a pointer to an interface on that object.  The two interfaces of most use are IPictureDisp and IPicture.  IPicture has a render method, into which a dc can be passed.  OleLoadPicturePath can load jpegs, bmps, gifs and icons - all that needs changing is the string in the first parameter.

Here is some example code.

IPicture* p1;

CComBSTR str(_T("C:\\Image.jpg"));

HRESULT hr = OleLoadPicturePath(str,     // path to load                    
                    NULL,  // IUnknown for aggregation
                    NULL,  // reserved
                             NULL,  // back colour
                                 IID_IPicture,  // interface to retrieve - must match type of p1
                             (void**)&p1);      // pointer to interface
0
 

Author Comment

by:Masonok
ID: 6180633
NickAtBOM!

Could you please create a small project based on Win32 Application (wizard) which is display "Image.jpg" somewhere on client area using OleLoadPicturePath in  WM_PAINT section.

and send the code of this project to : masonok@yahoo.com

0
 

Expert Comment

by:NickAtBOM
ID: 6180734
I'll post here rather than emailing so that everyone can read it...

There's no need for me to write something, as there is already just the application that you are looking for at the Microsoft support site.  Follow this link: http://support.microsoft.com/support/kb/articles/Q218/9/72.ASP
0
 

Author Comment

by:Masonok
ID: 6180836
It's exactly what I need!!!

Thanks a lot!
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6181385
HELLO???? Did any body read my first post???

"use the windows OleLoadPicture() function (search MSDN for LoadPic for an example)"

Sorry if that wasn't clear enough for you.


0
 

Expert Comment

by:NickAtBOM
ID: 6181491
Robpitt,

Sorry, didn't mean to steal your glory!

Your answer relies on OleLoadPicture() which relies on access to a stream object.  The MSDN says that the stream must be in BMP (bitmap), WMF (metafile), or ICO (icon) format.

First, I think Mansonok wanted to load directly from a disk without messing around with streams, so OleLoadPicturePath() is better.

Second, we are dealing with jpgs that OleLoadPicture() doesn't support.  Actually, I think this is rubbish - I'd be most supprised if you can't use OleLoadPicture() to get a jpg out of a stream, as all these calls are implemented using the ole picture object.
0
 
LVL 3

Expert Comment

by:qocarlos
ID: 6181665
NickAtBOM,

I suggested that OleLoadPicturePath works with jpeg files (see my first comment). You first proposed an answer when I believe you should just give a comment. Then if Masonok wanted more details he just had to ask.

Carlos
 
0
 

Expert Comment

by:NickAtBOM
ID: 6181856
Fair point and sorry - I'm new to this (only started today) and didn't realise how it all works...
0
 
LVL 3

Expert Comment

by:qocarlos
ID: 6181917
No problem :-) welcome to EE!
0
 

Author Comment

by:Masonok
ID: 6184381
I hope I am right with my decision. Inspite of that I gave points to NickAtBOM I want to thank ALL of YOU!
I am not an expert in C++ - I am a beginner (especially in OLE COM and stuff) so I look for a clear and more understandable answer. :)

Look at my question : Can you provide me with a SOURCE CODE - which is able to operate with JPEG-images using C++ and Win32API?

Because of : From MSDN
Remarks
The stream must be in BMP (bitmap), WMF (metafile), or ICO (icon) format... ? It doesn't mention about JPG - I was afraid that the answer is not correct... so I didn't go forward...
Also without an explanation I had no idea how to use OlePictureLoadPath. S0rry! :)

Look at my Math
Answers:
robpitt + gocarlos = NickAtBOM + NickAtBOM
(Sample) + function = function + direct link to a sample
So only NickAtBOM gave me the whole answer!

Please do not forget that person who asks a question may not be an expert! And in most cases it is not enough to say : Use this function! I believe that the small simple sample - always will be helpful!

Anyway I want to thank all of you because this dialog was VERY useful and helpful for me!!!!!!!!!!!! And I hope I can rely on your help in the future!

C U later! :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Suggested Courses

649 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