5,696,038 members and growing! (10,542 online)
Email Password   helpLost your password?
Multimedia » General Graphics » Image Display     Intermediate

CPicture - The Yovav (Horror) PictureShow

By Dr. Yovav Gad

Routines for displaying image files (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
VC6, C++Windows, NT4, Win2K, MFC, VS6, Visual Studio, Dev

Posted: 3 Oct 2001
Updated: 18 Jun 2003
Views: 227,875
Bookmarked: 69 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
68 votes for this Article.
Popularity: 8.47 Rating: 4.62 out of 5
0 votes, 0.0%
1
1 vote, 3.7%
2
2 votes, 7.4%
3
0 votes, 0.0%
4
24 votes, 88.9%
5

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Dr. Yovav Gad



Location: United States United States

Other popular General Graphics articles:

  • A flexible charting library for .NET
    Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use.
  • CxImage
    CxImage is a C++ class to load, save, display, transform BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX, TGA, WMF, WBMP, JBG, J2K images.
  • 3D Pie Chart
    A class library for drawing 3D pie charts.
  • Really cool visual FX
    A set of classes for doing stunning visual effects, including water, plasma and fire.
  • ImageStone
    An article on a library for image manipulation.
Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 117 (Total in Forum: 117) (Refresh)FirstPrevNext
GeneralHow to rotate ?memberhujunxi17:04 8 May '08  
GeneralJust one wordmemberDemian Panello16:17 7 Jun '07  
GeneralThanksmemberKaworu223:34 21 Mar '06  
GeneralHow do i use it for IDC_STATIC control?memberetboite23:05 10 Nov '05  
GeneralRe: How do i use it for IDC_STATIC control?memberK(arl)21:56 23 Feb '06  
GeneralRe: How do i use it for IDC_STATIC control?memberserup4:52 18 Sep '08  
GeneralDisplaying big images (need ScrollBar)memberangel42014:27 18 Aug '05  
GeneralPixel value ?memberangel42014:42 17 Aug '05  
GeneralRe: Pixel value ?memberChristian Graus15:39 17 Aug '05  
GeneralRe: Pixel value ?memberangel42014:01 18 Aug '05  
GeneralNice ClassmemberThatsAlok20:05 8 Jun '05  
GeneralCPicture to HBITMAPmembernaragana16:36 23 May '05  
GeneralRe: CPicture to HBITMAPmemberThatsAlok1:46 20 Jun '05  
Generalbug in CPictureShowDoc::CreateFilesListsussshay cohen23:22 4 Apr '05  
GeneralHelp!!!!!membersubbuviv0:24 31 Mar '05  
Generalchange pictures in Dialogmemberolis5:31 7 Feb '05  
GeneralRotating an ImagememberAlex Evans17:42 3 Jan '05  
GeneralRe: Rotating an ImagememberEinsteinJ0:53 26 Sep '05  
GeneralLoading a picture from an ftp sitememberrgarf4:48 3 Sep '04  
Generalproblem in image compression in databasememberKRANTHI KUMAR KUKKALA4:45 31 Aug '04  
Generalhow to get image data as pixels?membersgorgulu4:15 23 Aug '04  
Generalhelloo sir one problemmemberThatsAlok1:52 17 Jul '04  
GeneralIPictute and HBitmapmemberMirikos11:25 22 Jun '04  
GeneralRe: IPictute and HBitmapmembermcanti23:05 29 May '06  
GeneralUsing the Show Function not in OnPaintmemberJens Lengwenus2:32 18 May '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 Jun 2003
Editor: Nick Parker
Copyright 2001 by Dr. Yovav Gad
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project