CPicture - The Yovav (Horror) PictureShow

[CPictureShow.jpg]

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.

I created what I call a very *simple* and useful class. It can easily be implemented by adding it to a project. You don't have to be a real JPEG freak and invent all the header reading from the beginning (It uses the IPicture interface jst as Internet Explorer does)

About The Project

I Was a little carried away with this "ACDSee Alike" picture viewer. As it was not my main purpose - I didn't have the time to make it "Perfect". If you feel lucky and want to improve it here and there - please share it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  Picture (Implementations) Version 1.00

  Routines: 4 Showing Picture Files...
            (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  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();

  IPicture* m_IPicture; // Same As
             // LPPICTURE (typedef IPicture __RPC_FAR *LPPICTURE)

  LONG      m_Height; // Height (In Pixels Ignor What 
                      //      Current Device Context Uses)
  LONG      m_Weight; // Size Of The Image Object In 
                      //      Bytes (File OR Resource)
  LONG      m_Width;  // Width (In Pixels Ignor What 
                      //      Current Device Context Uses)
};
//~~~~~~~~~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
//
//  CPicture m_Picture;  // Create a Picture Object 
//                       //    (An Instance Of This Class)
//  #include "Picture.h" // Make Sure U Include This 
//                       //     Where U Gonna Create The Object...
//
//  Load Picture Data Into The IPicture Interface (.BMP 
//                         .DIB .EMF .GIF .ICO .JPG .WMF)
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  m_Picture.Load("Test.JPG"); // Load From a File - 
//                              //   Just Load It (Show Later)
//  m_Picture.Load(IDR_TEST, "JPG"); // Load From a Resource 
//                                   //- Just Load It (Show Later)
//  (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);)
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  m_Picture.UpdateSizeOnDC(&dc); // Get Picture Dimentions
//                                     //  In Pixels
//  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);
//
//~~~~~~~~~~~~~~~~~Cut The Bull Here~~~~~~~~~~~~~~~~~~~~~

Downloads

Download demo (SDI) project - 193Kb
Download source (CPicture class only) - 7Kb


Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds