Click here to Skip to main content
15,888,521 members
Articles / Desktop Programming / MFC

CPicture - The Yovav (Horror) PictureShow

Rate me:
Please Sign up or sign in to vote.
4.96/5 (34 votes)
18 Jun 2003CPOL 426K   10.8K   105   120
Routines for displaying image files (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)

After many days of searching (and not finding) a way to load a JPG from a resource and show it on a dialog based application, I decided to take steps

So I created what I call a very simple and useful class, it can easily be implemented by adding it to a project, and you do not have to be a real JPEG freak and invent all header reading from the beginning (it uses the IPicture interface - same way as Internet Explorer does)

About The Project

I was little carried away with this "ACDSee alike" picture viewer, as it was not my main purpose - I did not have the time to make it "perfect", if you feel lucky and want to improve it here and there then please share it with me.

COPYFREE (F) - ALL RIGHTS FREE

class CPicture
{
public:
	void FreePictureData();
	BOOL Load(CString sFilePathName);
	BOOL Load(UINT ResourceName, LPCSTR ResourceType);
	BOOL LoadPictureData(BYTE* pBuffer, int nSize);
	BOOL SaveAsBitmap(CString sFilePathName);
	BOOL Show(CDC* pDC, CPoint LeftTop, CPoint WidthHeight, int MagnifyX,
                  int MagnifyY);
	BOOL Show(CDC* pDC, CRect DrawRect);
	BOOL ShowBitmapResource(CDC* pDC, const int BMPResource, 
                                CPoint LeftTop);
	BOOL UpdateSizeOnDC(CDC* pDC);

	CPicture();
	virtual ~CPicture();
        // Same As LPPICTURE (typedef IPicture __RPC_FAR *LPPICTURE)
	IPicture* m_IPicture; 
	// Height (In Pixels Ignor What Current Device Context Uses)
	LONG m_Height; 	     
        // Size Of The Image Object In Bytes (File OR Resource) 
        LONG m_Weight;	
        // Width (In Pixels Ignor What Current Device Context Uses)
         LONG m_Width;  
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~Example & Usage 4 Dummies~~~~~~~~~~~~~~~~~~~~~~~~
//
//  U Need 2 Add "CPicture.CPP" and "CPicture.H" Into Your Project 
// (From FileView)
//  So U Will Get Control Over The Functions In This Class,
//  Then U Can Create a Picture Object And Show It On a Device Context
//
// Create a Picture Object (An Instance Of This Class)
//  CPicture m_Picture;  

// Make Sure U Include This Where U Gonna Create The Object...
//  #include "Picture.h" 
//  Load Picture Data Into The IPicture Interface 

(.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Load From a File - Just Load It (Show Later)
//	m_Picture.Load("Test.JPG"); 
// Load From a Resource - Just Load It (Show Later)
//	m_Picture.Load(IDR_TEST, "JPG"); 

//  (U Must Include IDR_TEST In Your Resources Under a Custom Name, 4 
//   Example - "JPG")
//  
//  When Using DC Object On a *Dialog Based* Application (CPaintDC dc(this);)
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	
// Get Picture Dimentions In Pixels
//      m_Picture.UpdateSizeOnDC(&dc); 
//	m_Picture.Show(&dc, CPoint(0,0), 
                       CPoint(m_Picture.m_Width, m_Picture.m_Height), 0,0);
//	
//      Change Original Dimentions
//      m_Picture.Show(&dc, CRect(0,0,100,100)); 

//      Show Bitmap Resource
//	m_Picture.ShowBitmapResource(&dc, IDB_TEST, CPoint(0,0)); 
//
//  OR When Using a Pointer On a "Regular" MFC Application (CDC* pDC)
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	m_Picture.UpdateSizeOnDC(pDC); // Get Picture Dimentions In Pixels
//	m_Picture.Show(pDC, CPoint(0,0),  CPoint
//                     m_Picture.m_Width,m_Picture.m_Height), 0,0);
//      Change Original Dimentions
//	m_Picture.Show(pDC, CRect(0,0,100,100)); 
//      Show Bitmap Resource
//	m_Picture.ShowBitmapResource(pDC, IDB_TEST, CPoint(0,0)); 
//  Show Picture Information
//  ~~~~~~~~~~~~~~~~~~~~~~~~
//	CString S;
//	S.Format("Size = %4d\nWidth = %4d\nHeight = %4d\nWeight = %4d\n",
//	         m_Picture.m_Weight, m_Picture.m_Width, 
//               m_Picture.m_Height,  m_Picture.m_Weight);
//	AfxMessageBox(S);
//

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President NEW media
United States United States
Creator of NEW media

Comments and Discussions

 
GeneralRe: bitmap from file... Pin
1-May-02 5:40
suss1-May-02 5:40 
GeneralRe: bitmap from file... Pin
yair241-May-02 6:05
yair241-May-02 6:05 
GeneralError When Use CPicture Pin
21-Apr-02 19:20
suss21-Apr-02 19:20 
GeneralRe: Error When Use CPicture Pin
25-Apr-02 20:19
suss25-Apr-02 20:19 
QuestionWhy can't I compile the rc file? Pin
kes16-Apr-02 20:41
kes16-Apr-02 20:41 
AnswerRe: Why can't I compile the rc file? Pin
25-Apr-02 20:11
suss25-Apr-02 20:11 
GeneralRe: Why can't I compile the rc file? Pin
13-May-02 13:32
suss13-May-02 13:32 
AnswerRe: Why can't I compile the rc file? Pin
14-May-02 4:21
suss14-May-02 4:21 
Maybe U should try choose some other language,

there might be something special on your system
(people arround the world did have success compiling it)

Anyway:

0x0d LANG_HEBREW Hebrew

0x01 SUBLANG_DEFAULT User Default


LANGUAGE on MSDN:


Primary Language Identifiers:

Identifier Predefined symbol Language
0x00 LANG_NEUTRAL Neutral
0x01 LANG_ARABIC Arabic
0x02 LANG_BULGARIAN Bulgarian
0x03 LANG_CATALAN Catalan
0x04 LANG_CHINESE Chinese
0x05 LANG_CZECH Czech
0x06 LANG_DANISH Danish
0x07 LANG_GERMAN German
0x08 LANG_GREEK Greek
0x09 LANG_ENGLISH English
0x0a LANG_SPANISH Spanish
0x0b LANG_FINNISH Finnish
0x0c LANG_FRENCH French
0x0d LANG_HEBREW Hebrew
0x0e LANG_HUNGARIAN Hungarian
0x0f LANG_ICELANDIC Icelandic
0x10 LANG_ITALIAN Italian
0x11 LANG_JAPANESE Japanese
0x12 LANG_KOREAN Korean
0x13 LANG_DUTCH Dutch
0x14 LANG_NORWEGIAN Norwegian
0x15 LANG_POLISH Polish
0x16 LANG_PORTUGUESE Portuguese
0x18 LANG_ROMANIAN Romanian
0x19 LANG_RUSSIAN Russian
0x1a LANG_CROATIAN Croatian
0x1a LANG_SERBIAN Serbian
0x1b LANG_SLOVAK Slovak
0x1c LANG_ALBANIAN Albanian
0x1d LANG_SWEDISH Swedish
0x1e LANG_THAI Thai
0x1f LANG_TURKISH Turkish
0x20 LANG_URDU Urdu
0x21 LANG_INDONESIAN Indonesian
0x22 LANG_UKRAINIAN Ukrainian
0x23 LANG_BELARUSIAN Belarusian
0x24 LANG_SLOVENIAN Slovenian
0x25 LANG_ESTONIAN Estonian
0x26 LANG_LATVIAN Latvian
0x27 LANG_LITHUANIAN Lithuanian
0x29 LANG_FARSI Farsi
0x2a LANG_VIETNAMESE Vietnamese
0x2b LANG_ARMENIAN Armenian
0x2c LANG_AZERI Azeri
0x2d LANG_BASQUE Basque
0x2f LANG_MACEDONIAN FYRO Macedonian
0x36 LANG_AFRIKAANS Afrikaans
0x37 LANG_GEORGIAN Georgian
0x38 LANG_FAEROESE Faeroese
0x39 LANG_HINDI Hindi
0x3e LANG_MALAY Malay
0x3f LANG_KAZAK Kazak
0x40 LANG_KYRGYZ Kyrgyz
0x41 LANG_SWAHILI Swahili
0x43 LANG_UZBEK Uzbek
0x44 LANG_TATAR Tatar
0x45 LANG_BENGALI Not supported.
0x46 LANG_PUNJABI Punjabi
0x47 LANG_GUJARATI Gujarati
0x48 LANG_ORIYA Not supported.
0x49 LANG_TAMIL Tamil
0x4a LANG_TELUGU Telugu
0x4b LANG_KANNADA Kannada
0x4c LANG_MALAYALAM Not supported.
0x4d LANG_ASSAMESE Not supported.
0x4e LANG_MARATHI Marathi
0x4f LANG_SANSKRIT Sanskrit
0x50 LANG_MONGOLIAN Mongolian
0x56 LANG_GALICIAN Galician
0x57 LANG_KONKANI Konkani
0x58 LANG_MANIPURI Not supported.
0x59 LANG_SINDHI Not supported.
0x5a LANG_SYRIAC Syriac
0x60 LANG_KASHMIRI Not supported.
0x61 LANG_NEPALI Not supported.
0x65 LANG_DIVEHI Divehi
0x7f LANG_INVARIANT


SubLanguage Identifiers:

Identifier Predefined symbol Language
0x00 SUBLANG_NEUTRAL Language neutral
0x01 SUBLANG_DEFAULT User Default
0x02 SUBLANG_SYS_DEFAULT System Default
0x01 SUBLANG_ARABIC_SAUDI_ARABIA Arabic (Saudi Arabia)
0x02 SUBLANG_ARABIC_IRAQ Arabic (Iraq)
0x03 SUBLANG_ARABIC_EGYPT Arabic (Egypt)
0x04 SUBLANG_ARABIC_LIBYA Arabic (Libya)
0x05 SUBLANG_ARABIC_ALGERIA Arabic (Algeria)
0x06 SUBLANG_ARABIC_MOROCCO Arabic (Morocco)
0x07 SUBLANG_ARABIC_TUNISIA Arabic (Tunisia)
0x08 SUBLANG_ARABIC_OMAN Arabic (Oman)
0x09 SUBLANG_ARABIC_YEMEN Arabic (Yemen)
0x0a SUBLANG_ARABIC_SYRIA Arabic (Syria)
0x0b SUBLANG_ARABIC_JORDAN Arabic (Jordan)
0x0c SUBLANG_ARABIC_LEBANON Arabic (Lebanon)
0x0d SUBLANG_ARABIC_KUWAIT Arabic (Kuwait)
0x0e SUBLANG_ARABIC_UAE Arabic (U.A.E.)
0x0f SUBLANG_ARABIC_BAHRAIN Arabic (Bahrain)
0x10 SUBLANG_ARABIC_QATAR Arabic (Qatar)
0x01 SUBLANG_AZERI_LATIN Azeri (Latin)
0x02 SUBLANG_AZERI_CYRILLIC Azeri (Cyrillic)
0x01 SUBLANG_CHINESE_TRADITIONAL Chinese (Traditional)
0x02 SUBLANG_CHINESE_SIMPLIFIED Chinese (Simplified)
0x03 SUBLANG_CHINESE_HONGKONG Chinese (Hong Kong SAR, PRC)
0x04 SUBLANG_CHINESE_SINGAPORE Chinese (Singapore)
0x05 SUBLANG_CHINESE_MACAU Chinese (Macau SAR)
0x01 SUBLANG_DUTCH Dutch
0x02 SUBLANG_DUTCH_BELGIAN Dutch (Belgian)
0x01 SUBLANG_ENGLISH_US English (US)
0x02 SUBLANG_ENGLISH_UK English (UK)
0x03 SUBLANG_ENGLISH_AUS English (Australian)
0x04 SUBLANG_ENGLISH_CAN English (Canadian)
0x05 SUBLANG_ENGLISH_NZ English (New Zealand)
0x06 SUBLANG_ENGLISH_EIRE English (Ireland)
0x07 SUBLANG_ENGLISH_SOUTH_AFRICA English (South Africa)
0x08 SUBLANG_ENGLISH_JAMAICA English (Jamaica)
0x09 SUBLANG_ENGLISH_CARIBBEAN English (Caribbean)
0x0a SUBLANG_ENGLISH_BELIZE English (Belize)
0x0b SUBLANG_ENGLISH_TRINIDAD English (Trinidad)
0x0c SUBLANG_ENGLISH_ZIMBABWE English (Zimbabwe)
0x0d SUBLANG_ENGLISH_PHILIPPINES English (Philippines)
0x01 SUBLANG_FRENCH French
0x02 SUBLANG_FRENCH_BELGIAN French (Belgian)
0x03 SUBLANG_FRENCH_CANADIAN French (Canadian)
0x04 SUBLANG_FRENCH_SWISS French (Swiss)
0x05 SUBLANG_FRENCH_LUXEMBOURG French (Luxembourg)
0x06 SUBLANG_FRENCH_MONACO French (Monaco)
0x01 SUBLANG_GERMAN German
0x02 SUBLANG_GERMAN_SWISS German (Swiss)
0x03 SUBLANG_GERMAN_AUSTRIAN German (Austrian)
0x04 SUBLANG_GERMAN_LUXEMBOURG German (Luxembourg)
0x05 SUBLANG_GERMAN_LIECHTENSTEIN German (Liechtenstein)
0x01 SUBLANG_ITALIAN Italian
0x02 SUBLANG_ITALIAN_SWISS Italian (Swiss)
0x01 SUBLANG_KOREAN Korean
0x01 SUBLANG_LITHUANIAN Lithuanian
0x01 SUBLANG_MALAY_MALAYSIA Malay (Malaysia)
0x02 SUBLANG_MALAY_BRUNEI_DARUSSALAM Malay (Brunei Darassalam)
0x01 SUBLANG_NORWEGIAN_BOKMAL Norwegian (Bokmal)
0x02 SUBLANG_NORWEGIAN_NYNORSK Norwegian (Nynorsk)
0x01 SUBLANG_PORTUGUESE_BRAZILIAN Portuguese (Brazil)
0x02 SUBLANG_PORTUGUESE Portuguese (Portugal)
0x02 SUBLANG_SERBIAN_LATIN Serbian (Latin)
0x03 SUBLANG_SERBIAN_CYRILLIC Serbian (Cyrillic)
0x01 SUBLANG_SPANISH Spanish (Castilian)
0x02 SUBLANG_SPANISH_MEXICAN Spanish (Mexican)
0x03 SUBLANG_SPANISH_MODERN Spanish (Spain)
0x04 SUBLANG_SPANISH_GUATEMALA Spanish (Guatemala)
0x05 SUBLANG_SPANISH_COSTA_RICA Spanish (Costa Rica)
0x06 SUBLANG_SPANISH_PANAMA Spanish (Panama)
0x07 SUBLANG_SPANISH_DOMINICAN_REPUBLIC Spanish (Dominican Republic)
0x08 SUBLANG_SPANISH_VENEZUELA Spanish (Venezuela)
0x09 SUBLANG_SPANISH_COLOMBIA Spanish (Colombia)
0x0a SUBLANG_SPANISH_PERU Spanish (Peru)
0x0b SUBLANG_SPANISH_ARGENTINA Spanish (Argentina)
0x0c SUBLANG_SPANISH_ECUADOR Spanish (Ecuador)
0x0d SUBLANG_SPANISH_CHILE Spanish (Chile)
0x0e SUBLANG_SPANISH_URUGUAY Spanish (Uruguay)
0x0f SUBLANG_SPANISH_PARAGUAY Spanish (Paraguay)
0x10 SUBLANG_SPANISH_BOLIVIA Spanish (Bolivia)
0x11 SUBLANG_SPANISH_EL_SALVADOR Spanish (El Salvador)
0x12 SUBLANG_SPANISH_HONDURAS Spanish (Honduras)
0x13 SUBLANG_SPANISH_NICARAGUA Spanish (Nicaragua)
0x14 SUBLANG_SPANISH_PUERTO_RICO Spanish (Puerto Rico)
0x01 SUBLANG_SWEDISH Swedish
0x02 SUBLANG_SWEDISH_FINLAND Swedish (Finland)
0x01 SUBLANG_URDU_PAKISTAN Urdu (Pakistan)
0x02 SUBLANG_URDU_INDIA Urdu (India)
0x01 SUBLANG_UZBEK_LATIN Uzbek (Latin)
0x02 SUBLANG_UZBEK_CYRILLIC Uzbek (Cyrillic)


have fun.


Best Regards - Yovav Gad
EMail: Yovav@SuperMain.com
Web-Site: www.SuperMain.com
GeneralDialog Pin
12-Apr-02 22:00
suss12-Apr-02 22:00 
GeneralRe: Dialog Pin
25-Apr-02 20:05
suss25-Apr-02 20:05 
GeneralRe: Dialog Pin
noudard2-Jul-02 11:22
noudard2-Jul-02 11:22 
GeneralRe: Dialog Pin
KienNT7815-Apr-08 16:12
KienNT7815-Apr-08 16:12 
Generalrotate Pin
30-Mar-02 9:32
suss30-Mar-02 9:32 
GeneralFrom where we can find the info abt: Pin
9-Mar-02 14:01
suss9-Mar-02 14:01 
Generaljpeg in a memory DC Pin
16-Feb-02 3:07
suss16-Feb-02 3:07 
GeneralDouble buffer implementation Pin
24-Jan-02 7:34
suss24-Jan-02 7:34 
GeneralRe: Double buffer implementation Pin
Yovav24-Jan-02 9:28
Yovav24-Jan-02 9:28 
GeneralConvrsion Pin
23-Jan-02 22:03
suss23-Jan-02 22:03 
GeneralRe: Convrsion Pin
Yovav24-Jan-02 1:48
Yovav24-Jan-02 1:48 
QuestionWhat poropse of this program? Pin
22-Jan-02 22:12
suss22-Jan-02 22:12 
GeneralPalette Pin
20-Jan-02 5:57
suss20-Jan-02 5:57 
GeneralCreateFilesList() fix Pin
typeiii12-Dec-01 6:09
typeiii12-Dec-01 6:09 
GeneralRe: CreateFilesList() fix Pin
Yovav12-Dec-01 11:28
Yovav12-Dec-01 11:28 
GeneralAnimation Pin
INC11-Dec-01 23:51
INC11-Dec-01 23:51 
GeneralASSERTS! File: filefind.cpp line 354 Pin
2-Nov-01 8:35
suss2-Nov-01 8:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.