当前位置: 首页>>代码示例>>C++>>正文


C++ CImage::GetColorTable方法代码示例

本文整理汇总了C++中CImage::GetColorTable方法的典型用法代码示例。如果您正苦于以下问题:C++ CImage::GetColorTable方法的具体用法?C++ CImage::GetColorTable怎么用?C++ CImage::GetColorTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CImage的用法示例。


在下文中一共展示了CImage::GetColorTable方法的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);
}
开发者ID:Ychuan1115,项目名称:ciratefi,代码行数:66,代码来源:ciratefiApp.cpp


注:本文中的CImage::GetColorTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。