本文整理汇总了C++中CImage::GetMaxColorTableEntries方法的典型用法代码示例。如果您正苦于以下问题:C++ CImage::GetMaxColorTableEntries方法的具体用法?C++ CImage::GetMaxColorTableEntries怎么用?C++ CImage::GetMaxColorTableEntries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CImage
的用法示例。
在下文中一共展示了CImage::GetMaxColorTableEntries方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ShowMatOnPicture
void CiratefiApp::ShowMatOnPicture(Mat& image, CDialog* dlg, int pID)
{
CRect PictureRect;
CStatic* PictureControl=(CStatic*)dlg->GetDlgItem(pID);
PictureControl->GetClientRect(&PictureRect);
CDC *pDc = PictureControl->GetWindowDC();
SetStretchBltMode(pDc->m_hDC,STRETCH_HALFTONE);
Mat resizeImage = image.clone();
if(resizeImage.rows>PictureRect.Height() || resizeImage.cols>PictureRect.Width())
{
double resizeRatio = min((double)PictureRect.Width()/(double)image.cols, (double)PictureRect.Height()/(double)image.rows);
resize(image, resizeImage, Size(), resizeRatio, resizeRatio);
}
CImage outputImage;
int width = resizeImage.cols;
int height = resizeImage.rows;
int channels = resizeImage.channels();
outputImage.Destroy(); //clear
outputImage.Create(width, height, 8*channels);
if(channels==1)
{
RGBQUAD* ColorTable;
int MaxColors=outputImage.GetMaxColorTableEntries();
ColorTable = new RGBQUAD[MaxColors];
outputImage.GetColorTable(0, MaxColors, ColorTable);
for (int i = 0; i < MaxColors; i++)
{
ColorTable[i].rgbBlue = (BYTE)i;
ColorTable[i].rgbGreen = (BYTE)i;
ColorTable[i].rgbRed = (BYTE)i;
}
outputImage.SetColorTable(0, MaxColors, ColorTable);
delete []ColorTable;
}
uchar* ps;
uchar* pimg = (uchar*)outputImage.GetBits(); //A pointer to the bitmap buffer
//The pitch is the distance, in bytes. represent the beginning of
// one bitmap line and the beginning of the next bitmap line
int step = outputImage.GetPitch();
for (int i = 0; i < height; ++i)
{
ps = (resizeImage.ptr<uchar>(i));
for ( int j = 0; j < width; j++ )
{
if ( channels == 1 ) //gray
{
*(pimg + i*step + j) = ps[j];
}
else if ( channels == 3 ) //color
{
for (int k = 0 ; k < 3; k++ )
{
*(pimg + i*step + j*3 + k ) = ps[j*3 + k];
}
}
}
}
outputImage.Draw(pDc->m_hDC, CRect(CPoint(PictureRect.TopLeft().x+(PictureRect.Width()-width)/2,PictureRect.TopLeft().y+(PictureRect.Height()-height)/2), CSize(width,height)));
dlg->ReleaseDC(pDc);
}