Available in the LEADTOOLS Imaging toolkit. |
RawLoad example for C++ 4.0 and later
//This example loads RAW data into a LEAD control.
//Raw data parameters are set in the LoadInfo event, which gets called
//when the file format is FILE_RAW, or any unrecognized file format.
//The LoadInfo event obtains information through class variables.
//class variables used in the LoadInfo event
// int nWidth; //width of image
// int nHeight; //height of image
// int nBitsPerPixel; //bits per pixel of image--if palettized, a gray palette is generated
// int nViewPerspective; //view perspective of raw data (TOP_LEFT, BOTTOM_LEFT, etc)
// int bOrderBGR; //TRUE if order BGR, FALSE if order RGB
// unsigned long nOffset; //offset into file where raw data begins
// int bPadding; //TRUE if each line of data is padded to four bytes
// int bReverseBits; //TRUE if the bits of each byte are reversed
void CRawDlg::RawLoad(char * pszFileName)
{
int nRet;
char szMsg[200];
//Fill in the class variables
//The class variables will get access in the LoadInfo event
nWidth = 294;
nHeight = 415;
nBitsPerPixel = 24;
nViewPerspective = BOTTOM_LEFT;
bOrderBGR = TRUE;
nOffset = 250;
bPadding = TRUE;
bReverseBits = TRUE;
nRet = m_Lead.Load(pszFileName, nBitsPerPixel, 0, 1);
if (nRet == 0)
wsprintf(szMsg, "SUCCESS file load: %s", pszFileName);
else
wsprintf(szMsg, "FAILED--file load: %s", pszFileName);
AfxMessageBox(szMsg);
}
void CRawDlg::OnLoadInfoLeadctrl1()
{
unsigned int uColors, i;
unsigned int uGray;
unsigned int uFlags;
m_Lead.SetScaleMode(3);
m_Lead.SetLoadInfoFormat(FILE_RAW);
m_Lead.SetLoadInfoWidth((float)nWidth);
m_Lead.SetLoadInfoHeight((float)nHeight);
m_Lead.SetLoadInfoBits(nBitsPerPixel);
m_Lead.SetLoadInfoXRes(150);
m_Lead.SetLoadInfoYRes(150);
m_Lead.SetLoadInfoOffset(nOffset);
uFlags = 0;
if (bPadding)
uFlags |= LOADINFO_PAD4;
if (bOrderBGR == FALSE)
uFlags |= LOADINFO_ORDERRGB;
if (bReverseBits)
uFlags |= LOADINFO_LSB;
switch(nViewPerspective)
{
case TOP_LEFT:
uFlags |= LOADINFO_TOPLEFT;
break;
case BOTTOM_LEFT:
uFlags |= LOADINFO_REVERSE;
break;
case TOP_RIGHT: //BOTTOM_LEFT180
uFlags |= LOADINFO_BOTTOMLEFT180;
break;
case BOTTOM_RIGHT: //TOP_LEFT180
uFlags |= LOADINFO_TOPLEFT180;
break;
case RIGHT_TOP: //TOP_LEFT90
uFlags |= LOADINFO_TOPLEFT90;
break;
case LEFT_BOTTOM: //TOP_LEFT270
uFlags |= LOADINFO_TOPLEFT270;
break;
case LEFT_TOP: //BOTTOM_LEFT90
uFlags |= LOADINFO_BOTTOMLEFT90;
break;
case RIGHT_BOTTOM: //BOTTOM_LEFT270
uFlags |= LOADINFO_BOTTOMLEFT270;
break;
}
//if image is palettized create a grayscale palette
if (nBitsPerPixel <= 8)
{
uColors = 1 << nBitsPerPixel;
uFlags |= LOADINFO_PALETTE;
for (i=0; i<uColors; i++)
{
uGray = (i * 256) / uColors;
m_Lead.SetUserPalette(i, RGB(uGray, uGray, uGray));
}
}
m_Lead.SetLoadInfoFlags(uFlags);
}