Solved

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

Posted on 2001-06-11
15
570 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
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 3

Expert Comment

by:qocarlos
Comment Utility
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
Comment Utility
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 150 total points
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:NickAtBOM
Comment Utility
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
Comment Utility
It's exactly what I need!!!

Thanks a lot!
0
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No problem :-) welcome to EE!
0
 

Author Comment

by:Masonok
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…

728 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