Click here to Skip to main content
15,887,676 members
Articles / Desktop Programming / MFC

FreeImage Display Demo

Rate me:
Please Sign up or sign in to vote.
3.98/5 (20 votes)
4 Jun 2008Public Domain17 min read 97.1K   10.4K   54  
How to display a bitmap in your MFC SDI application using FreeImage. Various rescaling algorithms considered.
//	FreeImage Display Demo v1.0

//	Copyright (C) 2008 monday2000@yandex.ru
//
//	This program is free software; you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation; either version 2 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program; if not, write to the Free Software
//	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//	http://www.gnu.org/copyleft/gpl.html

// fi_testDoc.h : interface of the CFi_testDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_FI_TESTDOC_H__6E1B28EB_2A56_11DC_82F4_CF7D89946643__INCLUDED_)
#define AFX_FI_TESTDOC_H__6E1B28EB_2A56_11DC_82F4_CF7D89946643__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "FreeImage.h"

class CFi_testDoc : public CDocument
{
protected: // create from serialization only
	CFi_testDoc();
	DECLARE_DYNCREATE(CFi_testDoc)

// Attributes
public:

// Operations
public:

FIBITMAP* m_dib;

FIBITMAP* m_dib2;

FIBITMAP* GenericLoader(const char* lpszPathName, int flag);

BITMAPINFO* m_pbi;

BITMAPINFOHEADER* m_pbih;

CString m_strFilename;

unsigned m_dib_width;

unsigned m_dib_height;


BYTE* m_pBits;

CBitmap m_OffscreenBitmap;

CBitmap* m_pOldBitmap;

CDC m_dcOffscreen;

int m_IsScrolledFlag;

unsigned m_height_shift, m_width_shift;	


HBITMAP CreateDibSectionFromFibitmap (PTSTR szFileName);

BOOL OpenBitmapFile(CString FileName);

BOOL m_MRU_CalledFlag;

double m_zoom;

double m_zoom_fit;

BOOL DisplayBitmap(double zoom);

unsigned m_view_init_height, m_view_init_width;

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFi_testDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CFi_testDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:	

// Generated message map functions
public: // <- here was "protected" originally. "Public" is made to
// allow the "void CFi_testView::OnLButtonDblClk(UINT nFlags, CPoint point)" method
	//{{AFX_MSG(CFi_testDoc)
	afx_msg void OnFileOpen();
	afx_msg void OnFileClose();
	afx_msg BOOL OnOpenRecentFile(UINT nID);
	afx_msg void OnUpdateFileSaveAs(CCmdUI* pCmdUI);
	afx_msg void OnUpdateFileClose(CCmdUI* pCmdUI);
	afx_msg void OnUpdateButtonFit(CCmdUI* pCmdUI);
	afx_msg void OnButtonFit();
	afx_msg void OnFileSaveAs();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FI_TESTDOC_H__6E1B28EB_2A56_11DC_82F4_CF7D89946643__INCLUDED_)

#define GRAPH_FILES_FILTER "Supported graphical formats \
|*.bmp;*.cut;*.dds;*.g3; \
*.gif;*.hdr;*.ico;*.iff;*.lbm;*.jng;*.jpg;*.jif;*.jpeg; \
*.jpe;*.koa;*.mng;*.pbm;*.pcd;*.pcx;*.pgm;*.png;*.ppm; \
*.psd;*.ras;*.sgi;*.tga;*.targa;*.tif;*.tiff;*.wap;*.wbmp; \
*.wbm;*.xbm;*.xpm| \
Windows or OS/2 Bitmap (*.bmp)|*.bmp| \
Dr. Halo (*.cut)|*.cut| \
DirectX Surface (*.dds)|*.dds| \
Raw fax format CCITT G.3 (*.g3)|*.g3| \
Graphics Interchange Format (*.gif)|*.gif| \
High Dynamic Range (*.hdr)|*.hdr| \
Windows Icon (*.ico)|*.ico| \
IFF Interleaved Bitmap (*.iff,*.lbm)|*.iff;*.lbm| \
JPEG Network Graphics (*.jng)|*.jng| \
JPEG-JFIF Compliant (*.jpg,*.jif,*.jpeg,*.jpe)|*.jpg;*.jif;*.jpeg;*.jpe| \
C64 Koala Graphics (*.koa)|*.koa| \
Multiple Network Graphics (*.mng)|*.mng| \
Portable Bitmap (ASCII) (*.pbm)|*.pbm| \
Portable Bitmap (RAW) (*.pbm)|*.pbm| \
Kodak PhotoCD (*.pcd)|*.pcd| \
Zsoft Paintbrush (*.pcx)|*.pcx| \
Portable Greymap (ASCII) (*.pgm)|*.pgm| \
Portable Greymap (RAW) (*.pgm)|*.pgm| \
Portable Network Graphics (*.png)|*.png| \
Portable Pixelmap (ASCII) (*.ppm)|*.ppm| \
Portable Pixelmap (RAW) (*.ppm)|*.ppm| \
Adobe Photoshop (*.psd)|*.psd| \
Sun Raster Image (*.ras)|*.ras| \
Silicon Graphics SGI image format (*.sgi)|*.sgi| \
Truevision Targa (*.tga,*.targa)|*.tga;*.targa| \
Tagged Image File Format (*.tif,*.tiff)|*.tif;*.tiff| \
Wireless Bitmap (*.wap,*.wbmp,*.wbm)|*.wap;*.wbmp;*.wbm| \
X11 Bitmap Format (*.xbm)|*.xbm| \
X11 Pixmap Format (*.xpm)|*.xpm| \
All files (*.*)|*.*||"

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions