Click here to Skip to main content
Licence CPOL
First Posted 3 Oct 2001
Views 301,280
Downloads 8,236
Bookmarked 91 times

CPicture - The Yovav (Horror) PictureShow

By | 18 Jun 2003 | Article
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)

About the Author

Yovav

CEO
MicroMighty, Inc.
United States United States

Member

CEO and founder of MicroMighty, Inc.
 
MicroMighty, Inc. - Software products, ASP.NET Components for developers, Social network services and more!

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questioncan any body encapsulates all this heap of code in one class usable with dialogbox control Pinmemberblackhack500019:05 15 Nov '10  
Generalimage in case of dialog box apps PinmemberSadru20:29 1 Mar '09  
QuestionHow to rotate ? Pinmemberhujunxi16:04 8 May '08  
GeneralJust one word PinmemberDemian Panello15:17 7 Jun '07  
GeneralThanks PinmemberKaworu222:34 21 Mar '06  
QuestionHow do i use it for IDC_STATIC control? Pinmemberetboite22:05 10 Nov '05  
AnswerRe: How do i use it for IDC_STATIC control? PinmemberK(arl)20:56 23 Feb '06  
I would rather derivate a class from CStatic, catch the WM_PAINT message and there process the drawing using m_Picture.
 




Pull the tapeworm out of your ass
Fold with us! ¤ flickr
AnswerRe: How do i use it for IDC_STATIC control? Pinmemberserup3:52 18 Sep '08  
GeneralDisplaying big images (need ScrollBar) Pinmemberangel42013:27 18 Aug '05  
QuestionPixel value ? Pinmemberangel42013:42 17 Aug '05  
AnswerRe: Pixel value ? PinmemberChristian Graus14:39 17 Aug '05  
GeneralRe: Pixel value ? Pinmemberangel42013:01 18 Aug '05  
GeneralNice Class PinmemberThatsAlok19:05 8 Jun '05  
GeneralCPicture to HBITMAP Pinmembernaragana15:36 23 May '05  
GeneralRe: CPicture to HBITMAP PinmemberThatsAlok0:46 20 Jun '05  
Generalbug in CPictureShowDoc::CreateFilesList Pinsussshay cohen22:22 4 Apr '05  
GeneralHelp!!!!! Pinmembersubbuviv23:24 30 Mar '05  
Generalchange pictures in Dialog Pinmemberolis4:31 7 Feb '05  
GeneralRotating an Image PinmemberAlex Evans16:42 3 Jan '05  
GeneralRe: Rotating an Image PinmemberEinsteinJ23:53 25 Sep '05  
GeneralLoading a picture from an ftp site Pinmemberrgarf3:48 3 Sep '04  
Generalproblem in image compression in database PinmemberKRANTHI KUMAR KUKKALA3:45 31 Aug '04  
Questionhow to get image data as pixels? Pinmembersgorgulu3:15 23 Aug '04  
Generalhelloo sir one problem PinmemberThatsAlok0:52 17 Jul '04  
GeneralIPictute and HBitmap PinmemberMirikos10:25 22 Jun '04  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 19 Jun 2003
Article Copyright 2001 by Yovav
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid