Class for reading bitmap

Source: Internet
Author: User

Today I wrote a class for reading bitmap and realized the package of A Class. When a data member is of the protected type, we wrote a function in the class to access this variable, like the attributes and methods in C.

////

This is the header file of the bitmap class.

DiB. h: interface for the CDIB class.
//
//////////////////////////////////////// //////////////////////////////

# If! Defined (afx_dib_hsf-acdea2b4_090a_4299_ab15_415423dec4c1_included _)
# Define afx_dib_h1_acdea2b4_090a_4299_ab15_415423dec4c1_included _

# If _ msc_ver> 1000
# Pragma once
# Endif // _ msc_ver> 1000

Class CDIB: Public cobject
{
Public:
CDIB ();
Virtual ~ CDIB ();
Protected:
Lpbitmapfileheader m_pbmfileheader;
Lpbitmapinfo m_pbminfo;
Lpbitmapinfoheader m_pbminfoheader;
Rgbquad * m_prgbtable;
Byte * m_pdibbits;
Uint m_numcolors;
Public:
Byte * getdibbitsptr ();
Lpbitmapinfo getdibinfoptr ();
Lpbitmapinfoheader getdibinfoheaderptr ();
Uint getdibheight ();
Uint getdibwidth ();
DWORD getdibsizeimage ();
CDIB (const char * filenmae );
Protected:
Void loadbitmapfile (const char * filename );
};

# Endif //! Defined (afx_dib_hsf-acdea2b4_090a_4299_ab15_415423dec4c1_included _)

 

 

 

 

 

 

 

 

 

 

 

 

This is the CPP File S.

 

/// Dib. cpp: Implementation of the CDIB class.
//
//////////////////////////////////////// //////////////////////////////

# Include "stdafx. H"
# Include "open. H"
# Include "dib. H"
# Include "windowsx. H"
# Ifdef _ debug
# UNDEF this_file
Static char this_file [] =__ file __;
# Define new debug_new
# Endif

//////////////////////////////////////// //////////////////////////////
// Construction/destruction
//////////////////////////////////////// //////////////////////////////

CDIB: CDIB ()
{
M_pbmfileheader = NULL;
M_pbminfo = NULL;
M_pbminfoheader = NULL;
M_prgbtable = 0;
M_pdibbits = 0;
}
CDIB: CDIB (const char * filename)
{
Loadbitmapfile (filename );
}

CDIB ::~ CDIB ()
{
Globalfree (m_pbminfo );
}
Void CDIB: loadbitmapfile (const char * filename)
{
Cfile file (filename, cfile: moderead );
Bitmapfileheader bmfileheader;
File. Read (void *) & bmfileheader, sizeof (bmfileheader ));
If (bmfileheader. bftype! = 0x4d42)
{
Afxmessagebox ("not a bitmap file ");
M_pbmfileheader = 0;
M_pbminfo = 0;
M_pbminfoheader = 0;
M_prgbtable = 0;
M_pdibbits = 0;
M_numcolors = 0;
}
Else
{
DWORD filelength = file. getlength ();
DWORD dibsize = filelength-sizeof (bmfileheader );


Byte * pdib = (byte *) globalallocptr (gmem_moveable, dibsize );
Pdib = new byte [dibsize];
File. Read (pdib, dibsize );
File. Close ();


M_pbminfo = (lpbitmapinfo) pdib;
M_pbminfoheader = (lpbitmapinfoheader) pdib;

M_pbminfoheader-> bisizeimage = getdibsizeimage ();

M_pdibbits = pdib + m_pbminfoheader-> bisize;
 
}
}
Dword cdib: getdibsizeimage ()
{
If (m_pbminfoheader-> bisizeimage = 0)
{
DWORD bytewidth = (DWORD) getdibwidth ();
DWORD Height = (DWORD) getdibheight ();
DWORD imagesize = bytewidth * height;
Return imagesize;
}
Else
Return m_pbminfoheader-> bisizeimage;
}
Uint CDIB: getdibwidth ()
{
Return (uint) m_pbminfoheader-> biwidth;

}
Uint CDIB: getdibheight ()
{
Return (uint) m_pbminfoheader-> biheight;
}
Lpbitmapinfoheader CDIB: getdibinfoheaderptr ()
{
Return m_pbminfoheader;
}
Lpbitmapinfo CDIB: getdibinfoptr ()
{
Return m_pbminfo;
}
Byte * CDIB: getdibbitsptr ()
{
Return m_pdibbits;

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.