Home > Software engineering >  Master genuflect is begged VC image processing problems
Master genuflect is begged VC image processing problems

Time:10-08

Consult ace: on the BMP images how to read the data? After opening the image data stored in where?
BOOL CImg: : AttachFromFile (LPCTSTR lpcPathName)
{
//using CFile object to simplify operations
CFile file;
If (! File. The Open (lpcPathName, CFile: : modeRead | CFile: : shareDenyWrite))
return FALSE;

BOOL bSuc=AttachFromFile (file);

File. The Close ();
Return bSuc;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
BOOL CImg: : AttachFromFile (CFile & amp; The file)

Function:
Open the specified image file and attached to the CImg object
Limitations:
Can only handle the bitmap image

Parameters:
CFile & amp; The file
To open the CFile object
The return value:
BYTE type, TRUE for success, FALSE for failure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

BOOL CImg: : AttachFromFile (CFile & amp; The file)
{
//file data
LPBYTE * lpData;
//bitmap information header
BITMAPINFOHEADER * pBMIH;
//add BITMAPFILEHEADER * pBMFH;
//BITMAPFILEHEADER * pBMFH;
//color table pointer
LPVOID lpvColorTable=NULL;
//color chart color number
Int nColorTableEntries;

BITMAPFILEHEADER bmfHeader;

//read the file header
If (! File. Read (& amp; BmfHeader, sizeof (bmfHeader)))
return FALSE;


//check if the first two bytes for BM
If (bmfHeader bfType!=MAKEWORD (' B ', 'M'))
{
return FALSE;
}

//read information head
PBMIH=(BITMAPINFOHEADER *) new BYTE [bmfHeader. BfOffBits - sizeof (bmfHeader)];
If (! File. Read (pBMIH, bmfHeader bfOffBits - sizeof (bmfHeader)))
{
The delete pBMIH;
return FALSE;
}

//test color table to locate
Int aa=sizeof (RGBQUAD);
Int bb=sizeof (BITMAPINFOHEADER);

NColorTableEntries=
(bmfHeader bfOffBits - sizeof (bmfHeader) - sizeof (BITMAPINFOHEADER))/sizeof (RGBQUAD);

If (nColorTableEntries & gt; 0)
{
LpvColorTable=pBMIH + 1;
}

PBMIH - & gt; BiHeight=abs (pBMIH - & gt; BiHeight);

//read image data WIDTHBYTES macro is used to generate the number of bytes per line
Int nWidthBytes=WIDTHBYTES ((pBMIH - & gt; BiWidth) * pBMIH - & gt; BiBitCount);

//application biHeight length is biWidthBytes array, use them to save the bitmap data
LpData=https://bbs.csdn.net/topics/new LPBYTE [(pBMIH -> biHeight)];
for(int i=0; i<(pBMIH - & gt; BiHeight); I++)
{
LpData [I]=new BYTE [nWidthBytes];
File. Read (lpData [I], nWidthBytes);

}

//update the data
The CleanUp ();


//////////////////////////////////////////////////////////////////////////
M_lpData=https://bbs.csdn.net/topics/lpData;
M_pBMIH=pBMIH;

M_lpvColorTable=lpvColorTable;
M_nColorTableEntries=nColorTableEntries;


Return TRUE;
}

CodePudding user response:

M_lpData=https://bbs.csdn.net/topics/lpData; Image data in m_lpData member variables, through m_lpData can access the image data,

CodePudding user response:

(1) on the BMP image data is the data?
(2) after the BITMAPFILEHEADER create bmfHeader data directly existed in the structure?
(3)! File. Read (& amp; BmfHeader bmfHeader, sizeof (bmfHeader) is the newly created structures, Read from where data Read address & amp; bmfHeader
  • Related