An Image (GIF, JPEG, BMP, ICO, WMF and EMF) Viewer

ImgViewer

Environment: Visual C++ 6.0 with Service Pack 3, Windows 9x, Windows NT 4.0 with Service Pack 6a and Windows 2000

This sample is an MFC application using the document/view architecture that can load, display, and print graphics files such aske GIF, JPEG, BMP (bitmap), ICO (icon), WMF (metafile), and EMF (Win32-enhanced metafile). It shows:

  • how to use the OleLoadPicturePath function and the IPicture interface to load and display those graphics files.

  • (Look into the ImgViewerDoc.cpp, ImgViewerView.cpp, and MainFrm.cpp files.)
  • how to support more than one file extension per MFC document type.

  • (Look into the MulExtDocTmp.cpp, MulExtDocTmp.h, and ImgViewer.cpp files.)

References:

Please see the following articles in the Microsoft Knowledge Base:

Q218972How To Load and Display Graphics Files w/LOADPIC.EXE
(Note that LOADPIC.EXE does not handle palettes. As a result, it won't display a 256-color image correctly in 256-color mode. Also, it uses the OleLoadPicture function instead of the OleLoadPicturePath function.)
Q141921HOWTO: How to Support Two File Extensions per MFC Document Type
Q198538DocMgrEx.exe Assoc Multiple File Extensions w/1 Doc Type

Downloads

Download Source Code - 153 KB


Comments

  • Does not support .jpg file created in CMYK color mode

    Posted by Priya_Sundar on 05/22/2008 04:54am

    I am not able to open a .jpg file, which in a CMYK color mode. How to provide support for such files?

    Reply
  • Pixel

    Posted by Legacy on 01/17/2004 12:00am

    Originally posted by: bassem

    your work is great, i hope you all the success
    can you help me please in converting an image to a matrix?
    have you any ideas about image watermarking? i need to insert some Data in an image..
    thanks a lot in advance, and good day Mr

    Reply
  • Great Example

    Posted by Legacy on 09/24/2003 12:00am

    Originally posted by: Edmond Chui

    It really helps me to learn how to display GIF in Windows application.

    Reply
  • How to load and display bitmap files on a dialog box by MFC

    Posted by Legacy on 01/21/2003 12:00am

    Originally posted by: Raymond Lai

    Dear Sir,

    I want to make a little program that can show all the bitmaps in a specific directory, like a photo browsing software.

    But i don't know how to do it. I just know how to open a file dialog box to choose the folder only. I don't know how to display a bitmap file on a static control(Frame control).
    and i don't know how to create it dainamically, as i don't know there are how many pictures in the folder.

    Can you send me the project and teach me how to do so?
    Thanks alot !!

    Have a nice day

    Raymond

    • Display a bitmap on dialog box

      Posted by lavanya_thanneru on 01/19/2006 04:40am

      I know how to display the bmp file on dialog box .But i have never displayed it on a static control.If u want to display a bmp on a static control then use Create() method of a CStatic  object this way...
      CStatic st;
      st.Creat(NULL,WS_CHILD|WS_VISIBLE|SS_BITMAP,CRect(10,10,400,400),this);
      
      //Code to display the bmp
      //szFileName is the name of bmp file
      HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,szFilename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
      	
         CBitmap bmp;
         bmp.Attach(hBmp);
         
         CClientDC dc(this);
         CDC bmDC;
         bmDC.CreateCompatibleDC(&dc);
         CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
      
         BITMAP  bi;
         bmp.GetBitmap(&bi);
         
         dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
      
         bmDC.SelectObject(pOldbmp);
      
         ::DeleteDC(bmDC);
         ::DeleteObject(pOldbmp);

      Reply
    Reply
  • help me!

    Posted by Legacy on 01/14/2003 12:00am

    Originally posted by: zhscx

    Can yon provide the recourse code of "*.img" format for me .
    Thank you very much!

    Reply
  • a simple image viewer

    Posted by Legacy on 01/11/2003 12:00am

    Originally posted by: abhinav tripathi

    its cool but can you tell how to do the same in straight c/c++ code (non mfc)so it would be suitable for me...

    Reply
  • Hard to get it runnung but wooha

    Posted by Legacy on 12/03/2002 12:00am

    Originally posted by: OMEGASquad

    Great program, you need to copy all these requested *.lib Files from the installation CD into the /LIB directory on your hraddrive, but when it's done you've got a real nice working program, good work boys...

    Reply
  • A very simple way to fix to the assertion failure under win98

    Posted by Legacy on 11/14/2002 12:00am

    Originally posted by: Francis Leca

    First i would to thank warmly Chen Su for his great code.

    It is very easy to get rid of the assertion failure when compiling the project under win98.

    Just change the project settings from Win32 Unicode Debug to Win32 Debug.

    That's all !

    Reply
  • VB-it's cool thing to do!

    Posted by Legacy on 10/14/2002 12:00am

    Originally posted by: spe@ker

    Hi from Russia!

    Reply
  • Can't open file "mfc42ud.lib"

    Posted by Legacy on 10/07/2002 12:00am

    Originally posted by: Grace

    I encounter this error during linking, it says "Fatal error link LNK1104: Can't open file mfc42ud.lib"


    I have resolve this problem already, i just re install my Visual Studio and include all the tools.

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds