Esempio n. 1
0
int HTMLImage(EE_Context* pContext, LPRECT lpRect, LPCTSTR lpText)
{
	CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, _T("Image Files(*.jpg;*.jpeg;*.jpe;*.png;*.gif;*.bmp)\0*.jpg;*.jpeg;*.jpe;*.png;*.gif;*.bmp\0All Files(*.*)\0*.*\0\0"));

	if( dlg.DoModal(pContext->hMain)==IDOK )
	{
		int w=-1;
		int h=-1;
		CImage img;
		if( img.Load( dlg.m_szFileName )==S_OK )
		{
			w=img.GetWidth();
			h=img.GetHeight();
			img.Destroy();
		}

		CString strText;
		if( w!=-1 )
			strText.Format(_T("<img src=\"%s\" width=\"%d\" height=\"%d\" border=\"0\" alt=\"$0\">"), dlg.m_szFileName, w, h);
		else
			strText.Format(_T("<img src=\"%s\" width=\"\" height=\"\" border=\"0\" alt=\"$0\">"), dlg.m_szFileName);

		HWND hWnd=(HWND)::SendMessage(pContext->hMain, EEM_GETACTIVETEXT, 0, 0);
		if( hWnd )
			::SendMessage(hWnd, ECM_INSERTSNIPPET, (WPARAM)(LPCTSTR)strText, strText.GetLength());
	}
	return 0;
}
Esempio n. 2
0
void CChildView::OnSrtpEnvironmentbrdf()
{
	CWaitCursor wait;//在函数执行过程中使鼠标图标变成等待图标
	int newX = 256, newY = 256;
	CImage tmpimg;
	tmpimg.Create(newX, newY, 24, 0);
	float NoV, roughness;
	float* res = new float[2];
	for (int x = 0; x < newX; x++){
		NoV = x*1.0f / newX;
		for (int y = 0; y < newY; y++){
			roughness = y*2.0f / newY;
			IntegrateBRDF(res, roughness, NoV);
			tmpimg.SetPixelRGB(x, y, (byte)(res[0] * 255), (byte)(res[1] * 255), 0);
		}
	}
	delete[] res;
	imgOriginal.Destroy();
	imgOriginal.Create(newX, newY, tmpimg.GetBPP());//根据新的大小建立CImage,GetBPP是获取其大小
	for (int x = 0; x < newX; x++){
		for (int y = 0; y < newY; y++){
			imgOriginal.SetPixel(x, y, tmpimg.GetPixel(x, y));
		}
	}
	tmpimg.Destroy();
	//刷新显示图像
	Invalidate();
	UpdateWindow();
}
Esempio n. 3
0
void CTreepadView::OnFileSaveAs()
{
	if (!tree.size()) {
		return;
	}
	BOOL isOpen = FALSE;
	CString defaultDir = L"D:\\Treepad\\Iteration";
	CString filter = L"PNG File (*.png)||";
	CString fileName = L"image1.png";         //默认打开的文件名
	CFileDialog openFileDlg(isOpen, L"png", fileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter, NULL);
	INT_PTR result = openFileDlg.DoModal();
	CString filePath = defaultDir + "\\" + fileName;
	if (result == IDOK) {
		filePath = openFileDlg.GetPathName();
		CRect rcBk;
		GetClientRect(&rcBk);
		CDC* pDC = GetDC();
		CImage Image;
		Image.Create(rcBk.Width(), rcBk.Height(), 24);
		::BitBlt(Image.GetDC(), 0, 0, rcBk.Width(), rcBk.Height(), pDC->m_hDC, 0, 0, SRCCOPY);
		Image.Save(filePath);
		Image.ReleaseDC();
		Image.Destroy();
	}
	// TODO: 在此添加命令处理程序代码
}
//绘画头像
void __cdecl CUserFaceRes::DrawNormalFace(CDC * pDC, int nXPos, int nYPos, WORD wFaceID, DWORD dwUserID, DWORD dwCustomFace)
{
	//调整参数
	if (wFaceID>=m_wCount) wFaceID=0;

	//绘画头像
	CDC DCFace;
	DCFace.CreateCompatibleDC(NULL);
	DCFace.SelectObject(m_NormalFace);
	bool bDrawFace = false;
	if(dwCustomFace!=0)
	{
		//头像名称
		CString strDirName;
		strDirName.Format(TEXT("%s\\CustomFace"),m_szDirWork);
		CString strFileName;
		strFileName.Format(TEXT("\\%ld_%d.bmp"), dwUserID, dwCustomFace);

		//读取文件
		CImage FaceImage;
		HRESULT hResult = FaceImage.Load(strDirName + strFileName);
		if (SUCCEEDED(hResult))
		{
			//设置模式
			int nOldBltMode = pDC->SetStretchBltMode(HALFTONE);

			//设置大小
			CRect rcFace;
			rcFace.left = nXPos;
			rcFace.top = nYPos;
			rcFace.right = rcFace.left + m_NormalSize.cx;
			rcFace.bottom = rcFace.top + m_NormalSize.cy;

			//绘画图片
			FaceImage.StretchBlt(pDC->GetSafeHdc(), rcFace);

			//删除资源
			pDC->SetStretchBltMode(nOldBltMode);
			FaceImage.Destroy();

			bDrawFace=true;
		}
	}

	//正常头像
	if(!bDrawFace) 
	{
		m_HeadImage.DrawImage(pDC, nXPos, nYPos, m_NormalSize.cx,m_NormalSize.cy,
			wFaceID*m_NormalSize.cx, 0, m_NormalSize.cx,m_NormalSize.cy);
		//AlphaDrawImage(pDC,nXPos,nYPos,m_NormalSize.cx,m_NormalSize.cy,&DCFace,wFaceID*m_NormalSize.cx,0);
	}

	return;
}
Esempio n. 5
0
MulRect CPicDlgQuery::GetWidthHeight(const string& path)
{
	CImage img;
	HRESULT hr = img.Load(CCharset::AnsiToUnicode(path).c_str());
	if (hr == S_OK)
	{
		MulRect rect = { 0, 0, img.GetWidth(), img.GetHeight() };
		img.Destroy();
		return rect;
	}
	return MulRect();
}
void CManualMotionCtlDlg::OnBnClickedButtonCapture()
{
	// TODO: Add your control notification handler code here

	DWORD dwSize;
	
	dwSize=theApp.m_VMRCap.GrabFrame ();
	if(dwSize>0)
	{
		BYTE *pImage;
		theApp.m_VMRCap.GetFrame (&pImage);
		//this->m_ctrlCaptureIMG .ShowImage (pImage);
	}


		int p = 0;
		CImage imageTransparentBack;
		imageTransparentBack.Create(2304, -1296, 24);

		BYTE* memTransparentBack = (BYTE*)imageTransparentBack.GetBits();

		if(dwSize > 0)
		{
			BYTE *pImage;

			dwSize=theApp.m_VMRCap.GetFrame(&pImage);

			for (int y=0;y<1296;y++)
			{
				for (int x=0; x<2304; x++)
				{
					memTransparentBack[p] = pImage[p];
					p++;
					memTransparentBack[p] = pImage[p];
					p++;
					memTransparentBack[p] = pImage[p];
					p++;
				}
			}

			 
			  char buffer [200];
			 // SetSnapshotFileName(buffer);
			  imageTransparentBack.Save("C:\\data\\temp.bmp");
	  
		}

		imageTransparentBack.Destroy();


}
Esempio n. 7
0
//重画函数
void CCardControl::OnPaint()
{
	CPaintDC dc(this);

	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

	//加载位图
	CImage ImageBuffer;
	CImageHandle HandleCard(&m_ImageCard);
	CImageHandle HandleFundus(&m_ImageBack);
	ImageBuffer.Create(rcClient.Width(),rcClient.Height(),16);
	if (ImageBuffer.IsNull()==true) return;

	//绘画扑克													                                              
	CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC());

     if(bDrawCard)																	               //add
     {																							   //add
	     for (int i=0;i<m_CardDataArray.GetCount();i++)				   				     
	     {
		   
			 BYTE bCardData=m_CardDataArray[i];
			 m_ImageCard.AlphaDrawImage(pBufferDC,i*CARD_SPACE,0,CARD_WIDTH,CARD_HEIGHT,GetCardXPos(bCardData),GetCardYPos(bCardData),RGB(255,0,255)); //非常好的画图函数
	     }
		    
	 }
    /////////////////////////////////////////////////////////////////////////////////////////begin add
     else																			
     {
		 
	    for(int i=0;i<m_CardDataArray.GetCount();i++)
	    {
			m_ImageBack.AlphaDrawImage(pBufferDC,i*CARD_SPACE,0,CARD_WIDTH,CARD_HEIGHT,3*CARD_WIDTH,4*CARD_HEIGHT,RGB(255,0,255));     //画扑克背面
		}
	 }
    ///////////////////////////////////////////////////////////////////////////////////////////end add
	ImageBuffer.ReleaseDC();
	ImageBuffer.BitBlt(dc,0,0);

	//清理资源
	ImageBuffer.Destroy();

   	return;
}
Esempio n. 8
0
void CTracer::SaveImageToFile(std::string fileName)
{
	CImage image;

	int width = m_camera.m_resolution.x;
	int height = m_camera.m_resolution.y;

	image.Create(width, height, 24);

	int pitch = image.GetPitch();
	unsigned char* imageBuffer = (unsigned char*)image.GetBits();

	if (pitch < 0)
	{
		imageBuffer += pitch * (height - 1);
		pitch = -pitch;
	}

	int i, j;
	int imageDisplacement = 0;
	int textureDisplacement = 0;

	for (i = 0; i < height; i++)
	{
		for (j = 0; j < width; j++)
		{
			glm::vec3 color = m_camera.m_pixels[textureDisplacement + j];

			// clamp(val, minVal, maxVal) = min(max(x, minVal), maxVal)
			// shows that val is in [minVal, maxVal]
			imageBuffer[imageDisplacement + j * 3] = unsigned(glm::clamp(color.b, 0.0f, 1.0f) * 255.0f);
			imageBuffer[imageDisplacement + j * 3 + 1] = unsigned(glm::clamp(color.g, 0.0f, 1.0f) * 255.0f);
			imageBuffer[imageDisplacement + j * 3 + 2] = unsigned(glm::clamp(color.r, 0.0f, 1.0f) * 255.0f);
		}

		imageDisplacement += pitch;
		textureDisplacement += width;
	}

	image.Save(fileName.c_str());
	image.Destroy();
}
void CTraffic_Camera_Image::MatToCImage(Mat &mat, CImage &cImage)
{
//create new CImage  
int width    = mat.cols;  
int height   = mat.rows;  
int channels = mat.channels();  
	
//cImage.ReleaseDC();
//cImage.ReleaseGDIPlus();
cImage.Destroy(); //clear  
cImage.Create(width,   
              height, //positive: left-bottom-up   or negative: left-top-down  
              8*channels ); //numbers of bits per pixel  

 //copy values  
uchar* ps;  
uchar* pimg = (uchar*)cImage.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 = cImage.GetPitch();  

	for (int i = 0; i < height; ++i)  
	{  
        ps = (mat.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];  
                }             
            }  
        }     
    }  

}
Esempio n. 10
0
// 从内存加载图片
BOOL ReadImage(const BYTE* buffer, ULONG size, CImage& img)
{
	// 创建流
	HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, size);
	BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
	if (pmem == NULL)
		return FALSE;
	memcpy(pmem, buffer, size);
	IStream* pstm;
	CreateStreamOnHGlobal(m_hMem, FALSE, &pstm);

	// 加载到CImage
	if (!img.IsNull())
		img.Destroy();
	img.Load(pstm);
	
	// 释放流
	GlobalUnlock(m_hMem);
	pstm->Release();
	return !img.IsNull();
}
Esempio n. 11
0
//绘画头像
void __cdecl CUserFaceRes::DrawCustomBigFace(CDC * pDC, int nXPos, int nYPos, DWORD dwUserID, DWORD dwCustomFace,UINT nWidth,UINT nHeight)
{
	ASSERT(dwUserID!=0 && dwCustomFace!=0);
	if(!(dwUserID!=0 && dwCustomFace!=0))return;

	//头像名称
	CString strDirName;
	strDirName.Format(TEXT("%s\\CustomFace"),m_szDirWork);
	CString strFileName;
	strFileName.Format(TEXT("\\%ld_%d.bmp"), dwUserID, dwCustomFace);

	//读取文件
	CImage FaceImage;
	HRESULT hResult = FaceImage.Load(strDirName + strFileName);
	if (SUCCEEDED(hResult))
	{
		//设置模式
		int nOldBltMode = pDC->SetStretchBltMode(HALFTONE);

		//设置大小
		CRect rcFace;
		rcFace.left = nXPos;
		rcFace.top = nYPos;
		rcFace.right = rcFace.left + nWidth;
		rcFace.bottom = rcFace.top + nHeight;

		//绘画图片
		FaceImage.StretchBlt(pDC->GetSafeHdc(), rcFace);

		//删除资源
		pDC->SetStretchBltMode(nOldBltMode);
		FaceImage.Destroy();
	}

	return;
}
Esempio n. 12
0
void CDrawWnd::draw_game_face(HWND hWnd,int TimeLength,int score)
{
	HDC hdc;
	hdc = GetDC(hWnd);
	HDC bgDC = CreateCompatibleDC(m_hdc);
	RECT rect;
	GetClientRect(hWnd,&rect);
	HBITMAP allBitmap = CreateCompatibleBitmap(hdc,rect.right - rect.left,
			rect.bottom - rect.top);
	SelectObject(bgDC, allBitmap);
	HBRUSH hBrush = CreateSolidBrush(RGB(255,255,255));
	SelectObject(bgDC,hBrush);
	Rectangle(bgDC,rect.left,rect.top,rect.right,rect.bottom);
	CImage image;
	image.Load( _T("res\\map\\游戏.bmp"));
	image.Draw(bgDC,0,0,image.GetWidth(),image.GetHeight());
	image.Destroy(); //释放image

	HPEN hPen1,hPen2,pen;
	pen = CreatePen(PS_SOLID,3,RGB(255,255,0));
	SelectObject(bgDC,pen);
	MoveToEx(bgDC,(a * 40 + 60),(b * 40 + 60),NULL);
	LineTo(bgDC,(c * 40 + 60),(d * 40 + 60));
	MoveToEx(bgDC,(e * 40 + 60),(f * 40 + 60),NULL);
	LineTo(bgDC,(g * 40 + 60),(h * 40 + 60));
	MoveToEx(bgDC,(aa * 40 + 60),(bb * 40 + 60),NULL);
	LineTo(bgDC,(cc * 40 + 60),(dd * 40 + 60));
	a = 0,b = 0,c = 0,d = 0,e = 0,f = 0,g = 0,h = 0,aa = 0,bb = 0,cc = 0,dd = 0;
	hPen2 = CreatePen(PS_NULL, 1, RGB(0, 0, 0));   //画笔 
	SelectObject(bgDC, hPen2); 
    hBrush = CreateSolidBrush(RGB(211, 211, 211)); //实心画刷 灰色
	SelectObject(bgDC, hBrush); 
	Rectangle(bgDC, 100, 20,640, 50); 

	hPen1 = CreatePen(PS_NULL, 1, RGB(0, 0, 0));   //画笔 
	SelectObject(bgDC, hPen1); 
	if(TimeLength>=20)
		hBrush = CreateSolidBrush(RGB(0, 128, 0)); //实心画刷 绿色
	else
		hBrush = CreateSolidBrush(RGB(255, 0, 0));////实心画刷 红色
	SelectObject(bgDC, hBrush); 
	Rectangle(bgDC, 100, 20,100+TimeLength*3, 50); 

	for (int iRow=0;iRow<12;iRow++)
	{
		for (int iCol=0;iCol<16;iCol++)
		{
			if(m_PicPos[iRow][iCol]!=0)
			{
				HDC memDC = CreateCompatibleDC(m_hdc);
				const TCHAR *p= m_pBmpPath[m_PicPos[iRow][iCol]-1];
				HBITMAP hh=(HBITMAP)LoadImage(m_hinst,p,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
				SelectObject(memDC,hh);

				CImage image;
				image.Load( p);
				image.Draw(memDC,0,0,image.GetWidth(),image.GetHeight());

				BitBlt(bgDC,40+iCol*40,40+iRow*40,40,40,memDC,0,0,SRCCOPY);
				DeleteObject(hh);
				DeleteDC(memDC);
			}
		}
	}

	int tscore=score;
	int tem=int(tscore/200);
	if(tscore>=1200)
		tem=0;
	for(int i=0;i<tem;i++)
	{
		HDC bgDC1 = CreateCompatibleDC(m_hdc);
		BITMAP temBmp;
		HBITMAP hStartBmp=(HBITMAP)LoadImage(m_hinst,TEXT("res\\map\\草1.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
		::GetObject(hStartBmp,sizeof(temBmp),&temBmp);
		SelectObject(bgDC1,hStartBmp);
		TransparentBlt(bgDC,120+i*60,500,60,60,bgDC1,0,0,temBmp.bmWidth,temBmp.bmHeight,RGB(255,255,255));
		DeleteObject(hStartBmp);
		//DeleteDC(bgDC);
	}
	if(tscore>=1200&&tscore<1600)
	{
		for(int i=0;i<6;i++)
		{
			HDC bgDC1 = CreateCompatibleDC(m_hdc);
			BITMAP temBmp;
			HBITMAP hStartBmp=(HBITMAP)LoadImage(m_hinst,TEXT("res\\map\\草1.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
			::GetObject(hStartBmp,sizeof(temBmp),&temBmp);
			SelectObject(bgDC1,hStartBmp);
			TransparentBlt(bgDC,120+i*60,500,60,60,bgDC1,0,0,temBmp.bmWidth,temBmp.bmHeight,RGB(255,255,255));
			DeleteObject(hStartBmp);
		}
	}
	if(tscore>=1600&&tscore<3600)
	{
		int n=int((tscore-1200)/400);
		for (int i=0;i<n;i++)
		{
			HDC bgDC1 = CreateCompatibleDC(m_hdc);
			BITMAP temBmp;
			HBITMAP hStartBmp=(HBITMAP)LoadImage(m_hinst,TEXT("res\\map\\草2.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
			::GetObject(hStartBmp,sizeof(temBmp),&temBmp);
			SelectObject(bgDC1,hStartBmp);
			TransparentBlt(bgDC,120+i*60,500,60,60,bgDC1,0,0,temBmp.bmWidth,temBmp.bmHeight,RGB(255,255,255));
			DeleteObject(hStartBmp);

		}
	}
	if(tscore>=3600&&tscore<4200)
	{
		for (int i=0;i<5;i++)
		{
			HDC bgDC1 = CreateCompatibleDC(m_hdc);
			BITMAP temBmp;
			HBITMAP hStartBmp=(HBITMAP)LoadImage(m_hinst,TEXT("res\\map\\草2.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
			::GetObject(hStartBmp,sizeof(temBmp),&temBmp);
			SelectObject(bgDC1,hStartBmp);
			TransparentBlt(bgDC,120+i*60,500,60,60,bgDC1,0,0,temBmp.bmWidth,temBmp.bmHeight,RGB(255,255,255));
			DeleteObject(hStartBmp);
		}
	}
	if(tscore>=4200)
	{
		int n=int((tscore-3600)/600);
		for (int i=0;i<n;i++)
		{
			HDC bgDC1 = CreateCompatibleDC(m_hdc);
			BITMAP temBmp;
			HBITMAP hStartBmp=(HBITMAP)LoadImage(m_hinst,TEXT("res\\map\\草3.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
			::GetObject(hStartBmp,sizeof(temBmp),&temBmp);
			SelectObject(bgDC1,hStartBmp);
			TransparentBlt(bgDC,120+i*60,500,60,60,bgDC1,0,0,temBmp.bmWidth,temBmp.bmHeight,RGB(255,255,255));
			DeleteObject(hStartBmp);
		}
	}
	BitBlt(m_hdc,0,0,900,600,bgDC,0,0,SRCCOPY);
	DeleteObject(allBitmap);
	DeleteObject(hBrush);
	DeleteDC(bgDC);
	DeleteObject(pen);
}
Esempio n. 13
0
//绘画背景
BOOL CUserInfoView::OnEraseBkgnd(CDC * pDC)
{
	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

	//建立缓冲
	CImage ImageBuffer;
	ImageBuffer.Create(rcClient.Width(),rcClient.Height(),24);

	//创建 DC
	CDC BufferDC;
	BufferDC.CreateCompatibleDC(pDC);
	BufferDC.SelectObject(ImageBuffer);

	//加载资源
	CImageHandle HandleTitleL(&m_ImageTitleL);
	CImageHandle HandleTitleM(&m_ImageTitleM);
	CImageHandle HandleTitleR(&m_ImageTitleR);

	//绘画背景
	m_ImageTitleL.BitBlt(BufferDC,0,0);

	//填充中间
	for (INT nXPos=m_ImageTitleL.GetWidth();nXPos<rcClient.Width();nXPos+=m_ImageTitleM.GetWidth())
	{
		m_ImageTitleM.BitBlt(BufferDC,nXPos,0);
	}

	//绘画背景
	m_ImageTitleR.BitBlt(BufferDC,rcClient.Width()-m_ImageTitleR.GetWidth(),0);

	//设置 DC
	BufferDC.SetTextColor(CR_TEXT);
	BufferDC.SetBkMode(TRANSPARENT);
	BufferDC.SelectObject(&CSkinAttribute::m_DefaultFont);

	//用户信息
	if (m_bShowInfo==true)
	{
		//变量定义
		tagGlobalUserData & GlobalUserInfo=g_GlobalUnits.GetGolbalUserData();

		//用户头像
		g_GlobalUnits.m_UserFaceRes->DrawNormalFace(&BufferDC,9,8,GlobalUserInfo.wFaceID);

		//构造位置
		TCHAR szBuffer[128]=TEXT("");
		CRect rcAccounts(50,11,rcClient.Width()-20,23);
		CRect rcUnderWrite(50,28,rcClient.Width()-20,40);

		//用户帐号
		_sntprintf(szBuffer,CountArray(szBuffer),TEXT("用户帐号:%s [ %ld ]"),GlobalUserInfo.szAccounts,GlobalUserInfo.dwGameID);
		BufferDC.DrawText(szBuffer,lstrlen(szBuffer),&rcAccounts,DT_VCENTER|DT_WORD_ELLIPSIS|DT_SINGLELINE);

		//个性签名
		_sntprintf(szBuffer,CountArray(szBuffer),TEXT("个性签名:%s"),GlobalUserInfo.szUnderWrite);
		BufferDC.DrawText(szBuffer,lstrlen(szBuffer),&rcUnderWrite,DT_VCENTER|DT_WORD_ELLIPSIS|DT_SINGLELINE);
	}

	//绘画界面
	pDC->BitBlt(0,0,rcClient.Width(),rcClient.Height(),&BufferDC,0,0,SRCCOPY);

	//清理资源
	BufferDC.DeleteDC();
	ImageBuffer.Destroy();

	return TRUE;
}
Esempio n. 14
0
int main()
{
	int a;//use for pause

	char readParaFlag;//if read the parameters (network) which have been trained
	//char modifyParaFlag;// if the user want to modify the training parameters
	bool needTrainningFlag=false;
	vector<vector<double> > inSet;
	vector<vector<double> > outSet;
	vector<vector<double> > testSet;
	vector<vector<double> > testoutSet;//use to calculate the hit ratio in test default
	vector<vector<double> > selfDefSet;
	vector<double> temp_vec;

	int sample_num = SAMPLE_NUM;
	int test_num = TEST_NUM;
	int input_dimension = INPUT_DIMENSION;
	int output_dimension = OUTPUT_DIMENSION;
	int hidden_layer_neuron_num = HIDDEN_LAYER_NEURON_NUM;
	int max_epoch = MAX_EPOCH;
	double trainning_speed = TRAINNING_SPEED;
	double min_error =MIN_ERROR;

	ifstream infile;
	ofstream outfile;//to save the parameters


	//deal with the trainning data
	CImage img;
	COLORREF pixel;
	int maxY=LENGTH;
	int maxX=LENGTH;
	int avg;
	byte r,g,b;
	string path;
	char temp_char[10];
	string temp_string;

	string pathHead="..\\Data\\Train\\";
	for (int i=0;i<OUTPUT_DIMENSION;++i){
		for (int j=1;j<=SAMPLE_NUM;++j){
			temp_string=itoa(j,temp_char,10);//change j to an int
			path=pathHead+char('0'+i)+" ("+temp_string+").bmp";
			img.Load((char*)path.data());
		//	maxY=img.GetHeight();
		//	maxX=img.GetWidth();
			for (int x=0;x<maxX;++x){
				for (int y=0;y<maxY;++y){
					pixel=img.GetPixel(x,y);
					r=GetRValue(pixel);  
					g=GetGValue(pixel);  
					b=GetBValue(pixel);
					avg=(int)((r+g+b)/3);
					if (avg>128) temp_vec.push_back(1);
					else temp_vec.push_back(0);
				}
			}
			inSet.push_back(temp_vec);
			temp_vec.clear();
			
			for (int x=0;x<i;++x) temp_vec.push_back(0);
			temp_vec.push_back(1);
			for (int x=i+1;x<OUTPUT_DIMENSION;++x) temp_vec.push_back(0);
			
			outSet.push_back(temp_vec);
			temp_vec.clear();

			img.Destroy();//important!!!!
		}
	}

	//deal with the test data
	pathHead="..\\Data\\Test_Default\\";
	for (int i=0;i<OUTPUT_DIMENSION;++i){
		for (int j=1;j<=TEST_NUM;++j){
			temp_string=itoa(j,temp_char,10);//change j to an int
			path=pathHead+char('0'+i)+" ("+temp_string+").bmp";
				img.Load((char*)path.data());
				//maxY=img.GetHeight();
				//maxX=img.GetWidth();
				for (int x=0;x<maxX;++x){
					for (int y=0;y<maxY;++y){
						pixel=img.GetPixel(x,y);
						r=GetRValue(pixel);  
						g=GetGValue(pixel);  
						b=GetBValue(pixel);
						avg=(int)((r+g+b)/3);
						if (avg>128) temp_vec.push_back(1);
						else temp_vec.push_back(0);
					}
				}
				testSet.push_back(temp_vec);
				temp_vec.clear();


				for (int x=0;x<i;++x) temp_vec.push_back(0);
				temp_vec.push_back(1);
				for (int x=i+1;x<OUTPUT_DIMENSION;++x) temp_vec.push_back(0);
				testoutSet.push_back(temp_vec);
				temp_vec.clear();
				
				img.Destroy();
		}
	}

	/*cout<<"Do you need to read the trained parameters? y or n >> ";
	cin>>modifyParaFlag;
	if (modifyParaFlag=='y'){
		needTrainningFlag = true;
	}
	*/
	NeuralNet network(INPUT_DIMENSION,OUTPUT_DIMENSION,HIDDEN_LAYER_NEURON_NUM,TRAINNING_SPEED,MAX_EPOCH,MIN_ERROR);
	
	
	cout<<"Do you need to read the trained parameters? y or n >> ";
	cin>>readParaFlag;
	if (readParaFlag=='y'){
		needTrainningFlag=false;
		infile.open("..\\Trained_Parameters.txt");
		network.readParameter(infile);
		infile.close();
	}
	else if (readParaFlag=='n'){
		needTrainningFlag=true;
		outfile.open("..\\Trained_Parameters.txt");
		network.train(inSet,outSet);
		network.saveParameter(outfile);
		outfile.close();
	}
	else {
		cout<<"error input!\n";
		return -1;
	}
	cout<<endl<<endl;


	//default test
	int count=0;
	int hitcount=0;
	for (int i=0;i<OUTPUT_DIMENSION;++i)
	{
		for (int j=0;j<TEST_NUM;++j)
		{
			network.calculateOutput(testSet[count],temp_vec);
			cout<<"recognize bmp "<<i<<"("<<j+1<<")"<<endl;
			for (int k=0;k<OUTPUT_DIMENSION;++k) cout<<temp_vec[k]<<" ";
			cout<<endl;
			int index=0;
			for (int k=0;k<OUTPUT_DIMENSION;++k){
				if (temp_vec[k]>temp_vec[index]) index=k;
			}
			cout<<"This number is likely to be "<<index<<endl;
			if (testoutSet[count][index]==1) {cout<<"hit\n";++hitcount;}
			temp_vec.clear();
			++count;
		}
	}

	cout<<"------------------------------------------\n";
	cout<<"Hit ratio: "<<double(hitcount)/count<<endl;


	int self_define_num;
	cout<<"\nPlz input the image number you want to recognize>> ";
	cin>>self_define_num;
	

	pathHead="..\\Data\\Test_User\\";
	for (int i=0;i<self_define_num;++i){
			// if input n need bmp from 0.bmp to N-1.bmp
			temp_string=itoa(i,temp_char,10);//change j to an int
			path=pathHead+temp_string+".bmp";
			img.Load((char*)path.data());
				for (int x=0;x<maxX;++x){
					for (int y=0;y<maxY;++y){
						pixel=img.GetPixel(x,y);
						r=GetRValue(pixel);  
						g=GetGValue(pixel);  
						b=GetBValue(pixel);
						avg=(int)((r+g+b)/3);
						if (avg>128) temp_vec.push_back(1);
						else temp_vec.push_back(0);
					}
				}
				selfDefSet.push_back(temp_vec);
				temp_vec.clear();
				img.Destroy();
	}

	for (int i=0;i<self_define_num;++i){
			network.calculateOutput(selfDefSet[i],temp_vec);
			cout<<"recognize "<<i<<".bmp"<<endl;
			//for (int k=0;k<OUTPUT_DIMENSION;++k) cout<<temp_vec[k]<<" ";
			//cout<<endl;
			int index=0;
			for (int k=0;k<OUTPUT_DIMENSION;++k){
				if (temp_vec[k]>temp_vec[index]) index=k;
			}
			cout<<"This number is likely to be "<<index<<endl;
			temp_vec.clear();
	}

	cout<<"Press any key and enter to exit>> ";
	cin>>a;
	return 0;
}
Esempio n. 15
0
//绘画头像
void __cdecl CUserFaceRes::DrawNormalFace(CDC * pDC, int nXPos, int nYPos, WORD wFaceID, DWORD dwUserID, DWORD dwCustomFace,DWORD X,DWORD Y)
{
	//调整参数
	if (wFaceID>=m_wCount) wFaceID=0;

	//绘画头像
	CDC DCFace;
	DCFace.CreateCompatibleDC(NULL);
	DCFace.SelectObject(m_NormalFace);

	//////////////////////////////////////////////////////////////////////////
	CDC DCFaceGril;
	DCFaceGril.CreateCompatibleDC(NULL);
	DCFaceGril.SelectObject(m_FaceGirl);

	CDC DCFaceBoby;
	DCFaceBoby.CreateCompatibleDC(NULL);
	DCFaceBoby.SelectObject(m_FaceBoby);
	//////////////////////////////////////////////////////////////////////////

	bool bDrawFace = false;
	if(dwCustomFace!=0)
	{
		//头像名称
		CString strDirName;
		strDirName.Format(TEXT("%s\\CustomFace"),m_szDirWork);
		CString strFileName;
		strFileName.Format(TEXT("\\%ld_%d.bmp"), dwUserID, dwCustomFace);

		//读取文件
		CImage FaceImage;
		HRESULT hResult = FaceImage.Load(strDirName + strFileName);
		if (SUCCEEDED(hResult))
		{
			//设置模式
			int nOldBltMode = pDC->SetStretchBltMode(HALFTONE);

			//设置大小
			CRect rcFace;
			rcFace.left = nXPos;
			rcFace.top = nYPos;
			rcFace.right = rcFace.left + m_NormalSize.cx;
			rcFace.bottom = rcFace.top + m_NormalSize.cy;

			//绘画图片
			FaceImage.StretchBlt(pDC->GetSafeHdc(), rcFace);

			//删除资源
			pDC->SetStretchBltMode(nOldBltMode);
			FaceImage.Destroy();

			bDrawFace=true;
		}
	}

	//正常头像
	if(!bDrawFace) 
	{

		//m_NormalFace.StretchBlt(pDC->GetSafeHdc(), nXPos, nYPos, 32, 32, 0,0,0,0);
		AlphaDrawImage(pDC,nXPos,nYPos,m_NormalSize.cx,m_NormalSize.cy,&DCFace,wFaceID*m_NormalSize.cx,0,X, Y);

// 		//设置大小
// 		CRect rcFace;
// 		rcFace.left = nXPos;
// 		rcFace.top = nYPos;
// 		rcFace.right = rcFace.left + X;
// 		rcFace.bottom = rcFace.top + Y;
// 
// 		if(wFaceID==0)
//  		{
// 			//头像名称
// 			CSize szFace = CSize(X,Y);
// 			AlphaDrawImage(pDC,nXPos,nYPos,szFace.cx,szFace.cy,&DCFaceGril,0,0);
// 
//  		}else
// 		{
// 		  	//头像名称
// 			CSize szFace = CSize(X,Y);
// 			AlphaDrawImage(pDC,nXPos,nYPos,szFace.cx,szFace.cy,&DCFaceBoby,0,0);
// 		//	m_FaceBoby.AlphaDrawImage(pDC, nXPos, nYPos, RGB(255,0,255));
// 		}
		
	}

	return;
}
Esempio n. 16
0
void CP1::main_do()
{
	

CClientDC dc(this);

//下面是图片路径    
zstringEx imgpath,zs;
imgpath.getCtlText(IDC_EDIT2,this->m_hWnd);
imgpath.trim();
if(imgpath.getStringLen()>0)
{
	if(imgpath[imgpath.getStringLen()-1]!='\\')imgpath+='\\';		
}
//上面是取得图片路径

	        


	//////////////////////////////////////////////按序选文件
	zs=imgpath.v();


	   
		zs+=  face_img_dir[cur_order].name;cur_order++;
		//zs.setCtlText(IDC_EDIT4);
		zs.replaceB(0,".jpg",".bmp");  //如果是JPG文件,暂换为BMP
		zs.replaceB(0,".JPG",".bmp");
		                                 //从按序从枚举数组中取出文件名
	
	
	

	////////////////////////////////////////////按序选文件





	//下面是把JPG转为BMP
	if( !zstringEx::is_file_exist(zs.v())  )
	{
		zs.replaceB(0,".bmp",".jpg");
		if(!zstringEx::is_file_exist(zs.v()))return;

		DRAWPIC.Destroy();
		DRAWPIC.Load(zs.v());
				
		zstringEx zs2;zs2.tools_GetCurDir();
		zs2+="\\jpg2bmp.bmp";  //统一转化为BMP来进行
		DRAWPIC.Save(zs2.v());
		zs=zs2.v();		
	}
	
    DRAWPIC.Destroy();
	DRAWPIC.Load(zs.v());


//if(DRAWPIC.GetWidth()>601)goto loopfor_only_320_small_pic; //大小限制,临时用的



	//下面是把BMP进行缩小,过大的
	if(DRAWPIC.GetWidth()>MY_IMAGE_MAX_WIDTH)
	{
		SMALLPIC.Create(MY_IMAGE_MAX_WIDTH,
			            DRAWPIC.GetHeight()/((float)DRAWPIC.GetWidth()/MY_IMAGE_MAX_WIDTH),
						24);

		HDC hdc=SMALLPIC.GetDC();

		::SetStretchBltMode(hdc,COLORONCOLOR);

		DRAWPIC.Draw(hdc,0,0,SMALLPIC.GetWidth(),SMALLPIC.GetHeight(),0,0,DRAWPIC.GetWidth(),DRAWPIC.GetHeight());
        

		zstringEx zs2;zs2.tools_GetCurDir();
		zs2+="\\cur_small.bmp";  //统一转化为BMP来进行
		SMALLPIC.Save(zs2.v());
        zs=zs2.v();

		SMALLPIC.ReleaseDC();
        SMALLPIC.Destroy();

         DRAWPIC.Destroy();
	     DRAWPIC.Load(zs.v());//重装入
	}



    //下面是把BMP进行缩小,过大的
	if(DRAWPIC.GetHeight()>MY_IMAGE_MAX_HEIGHT)
	{
		SMALLPIC.Create(DRAWPIC.GetWidth()/((float)DRAWPIC.GetHeight()/MY_IMAGE_MAX_HEIGHT),
			            MY_IMAGE_MAX_HEIGHT,
						24);

		HDC hdc=SMALLPIC.GetDC();
        ::SetStretchBltMode(hdc,COLORONCOLOR);
		DRAWPIC.Draw(hdc,0,0,SMALLPIC.GetWidth(),SMALLPIC.GetHeight(),0,0,DRAWPIC.GetWidth(),DRAWPIC.GetHeight());
        

		zstringEx zs2;zs2.tools_GetCurDir();
		zs2+="\\cur_small2.bmp";  //统一转化为BMP来进行
		SMALLPIC.Save(zs2.v());
        zs=zs2.v();

		SMALLPIC.ReleaseDC();
        SMALLPIC.Destroy();

        DRAWPIC.Destroy();
	    DRAWPIC.Load(zs.v());//重装入
	}


	this->RedrawWindow();//去掉原来的
    DRAWPIC.Draw(dc,0,0);//在窗口上画图




 

//1.人脸检测
long zret= zFaceLocate( OID,                     //第一个函数返回的人脸识别实例对象ID
						zs.v(),               //图像文件名,JPG,BMP
						cur_max_out_nums,            //用户要求的最大人脸输出数
						cur_sel_threshold,              //人脸置信度阀值,高于这个阀值才会被输出
						ofs); 
//2.报错信息    
if(zret<0)
{
	char er[256];
	zGetLastError(OID,er);
	AfxMessageBox(er);
}


	//CClientDC dc(this);
   POINT of;of.x=0;of.y=0;
   CString sbwh;
	for(int k=0;k<zret;k++)
	{   		
		//3.标记出选中的人脸
        zFlagFace(OID,(LONG)this->m_hWnd,k,0,0);

		sbwh.Format("E1_W: %d E1_H: %d E2_W: %d E2_H: %d",ofs[k].eye1_w,ofs[k].eye1_h,ofs[k].eye2_w,ofs[k].eye2_h);
        GetDlgItem(6677)->SetWindowText(sbwh);

		//dc.Rectangle(ofs[k].eye1_x-ofs[k].eye1_w/2,
		//	ofs[k].eye1_y-ofs[k].eye1_h/2,
		//	ofs[k].eye1_x+ofs[k].eye1_w/2,
		//	ofs[k].eye1_y+ofs[k].eye1_h/2) ;
		//dc.Rectangle(ofs[k].eye2_x-ofs[k].eye2_w/2,
		//	ofs[k].eye2_y-ofs[k].eye2_h/2,
		//	ofs[k].eye2_x+ofs[k].eye2_w/2,
		//	ofs[k].eye2_y+ofs[k].eye2_h/2) ;
	


		//4.在其下打分
		CString outdf;
		outdf.Format("%d: %0.2f",k+1,ofs[k].tally);
        dc.TextOut(ofs[k].left,ofs[k].bottom,outdf);
		
	}
	 
//5.回收人脸检测内存
    zFaceLocate_FreeMemory(OID);

}//end func
Esempio n. 17
0
BOOL CPlayerToolBar::Create(CWnd* pParentWnd)
{
    VERIFY(__super::CreateEx(pParentWnd,
                             TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_AUTOSIZE | TBSTYLE_CUSTOMERASE,
                             WS_CHILD | WS_VISIBLE | CBRS_BOTTOM | CBRS_TOOLTIPS,
                             CRect(2, 2, 0, 1)));

    VERIFY(LoadToolBar(IDB_PLAYERTOOLBAR));

    // Should never be RTLed
    ModifyStyleEx(WS_EX_LAYOUTRTL, WS_EX_NOINHERITLAYOUT);

    CToolBarCtrl& tb = GetToolBarCtrl();
    tb.DeleteButton(tb.GetButtonCount() - 1);
    tb.DeleteButton(tb.GetButtonCount() - 1);

    SetMute(AfxGetAppSettings().fMute);

    UINT styles[] = {
        TBBS_CHECKGROUP, TBBS_CHECKGROUP, TBBS_CHECKGROUP,
        TBBS_SEPARATOR,
        TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON,
        TBBS_SEPARATOR,
        TBBS_BUTTON,
        TBBS_SEPARATOR,
        TBBS_SEPARATOR,
        TBBS_CHECKBOX,
    };

    for (int i = 0; i < _countof(styles); ++i) {
        // This fixes missing separator in Win 7
        if (styles[i] & TBBS_SEPARATOR) {
            SetButtonInfo(i, GetItemID(i), styles[i], -1);
        } else {
            SetButtonStyle(i, styles[i] | TBBS_DISABLED);
        }
    }

    m_volctrl.Create(this);
    m_volctrl.SetRange(0, 100);

    m_nButtonHeight = 16; // reset m_nButtonHeight
    CImage image;
    if (LoadExternalToolBar(&image)) {
        CBitmap* bmp = CBitmap::FromHandle(image);
        int width = image.GetWidth();
        int height = image.GetHeight();
        int bpp = image.GetBPP();
        if (width == height * 15) {
            // the manual specifies that sizeButton should be sizeImage inflated by (7, 6)
            SetSizes(CSize(height + 7, height + 6), CSize(height, height));

            m_pButtonsImages = DEBUG_NEW CImageList();
            if (bpp == 32) {
                m_pButtonsImages->Create(height, height, ILC_COLOR32 | ILC_MASK, 1, 0);
                m_pButtonsImages->Add(bmp, nullptr); // alpha is the mask
            } else {
                m_pButtonsImages->Create(height, height, ILC_COLOR24 | ILC_MASK, 1, 0);
                m_pButtonsImages->Add(bmp, RGB(255, 0, 255));
            }
            m_nButtonHeight = height;
            GetToolBarCtrl().SetImageList(m_pButtonsImages);
        }
        image.Destroy();
    }

    return TRUE;
}
Esempio n. 18
0
// Callback function ----------------------------------------------------------
void testcallback(IplImage* img)
{
    assert (img);
    lastframe.Destroy();
    lastframe.Create(img->width,img->height,24,img->origin);
    lastframe.CopyOf(img);
    
    if (view.m_track) {

        if (!view.m_trackinit) {
            view.StartTracking(lastframe);
            view.m_trackinit = true;
        }

        view.TrackFeatures(lastframe);
        
        //double kx = (double)view.m_w/img->width;
        //double ky = (double)view.m_h/img->height;
        
        if( !view.m_night_mode )
        {
            
        }
        else
        {
            //iplSet( img, 0 );
            CvPoint tl = {0,0};
            CvPoint br = {img->width,img->height};
            //cvRectangle(img, tl, br, 0, (img->width > img->height) ? img->width : img->height);
            //cvRectangle(img, tl, br, 0, 255);
            memset(img->imageData,0,img->imageSize);
        }
        
        int i, count = view.m_tracker.GetCount();
        const PointArray& array = view.m_tracker.GetPoints();

        cvCircle( img, P, cvRound(3), CV_RGB(0,0,255));
                
        for( i = 0; i < count; i++ )
        {
            CvPoint pt;
            int color;
            if( i != view.m_moved_idx )
            {
                pt = cvPoint( cvRound(array[i].x), cvRound(array[i].y));
                color = CV_RGB(0,255,0);
            }
            else
            {
                pt = cvPoint( cvRound(view.m_moved_point.x),
                    cvRound(view.m_moved_point.y));
                color = CV_RGB(255,0,0);
            }
            cvCircle( img, pt, 1, color, CV_FILLED );
        }
    }
    else
    {
        if  (view.m_trackinit)
        {
            view.StopTracking();
            view.m_trackinit = false;
        }
    }
    
#ifdef WIN32
    Sleep(10);
#endif
}
Esempio n. 19
0
bool CScene::OnProcessingWindowMessage(HWND hWnd, UINT nMessageID, WPARAM wParam, LPARAM lParam)
{
    switch (nMessageID)
    {
    case WM_DROPFILES:
    {
        HDROP hDrop = (HDROP)wParam;
        TCHAR szPathFileName[MAX_PATH + 1];
        DragQueryFile(hDrop, 0, szPathFileName, MAX_PATH);

        if (m_cImage) {
            DeleteObject(m_cImage);
            m_cImage = nullptr;
        }
        if (m_hIcon) {
            DestroyIcon(m_hIcon);
            m_hIcon = nullptr;
        }

        std::wstring strExtension(PathFindExtension(szPathFileName));
        if (   strExtension == TEXT(".png")
                || strExtension == TEXT(".jpg")
                || strExtension == TEXT(".bmp")
                || strExtension == TEXT(".jpeg")
                || strExtension == TEXT(".PNG")
                || strExtension == TEXT(".JPG")
                || strExtension == TEXT(".JPEG")
                || strExtension == TEXT(".BMP")
           )
        {
            CImage m_cImageSumnail;
            m_cImageSumnail.Load(szPathFileName);

            float height = (float)m_cImageSumnail.GetHeight();
            float width = (float)m_cImageSumnail.GetWidth();
            bool bStand = false;
            int space = 0;
            if (height > width) {
                bStand = true;
                width /= height;
                height = 1;
            }
            else if (height < width) {
                bStand = false;
                height /= width;
                width = 1;
            }
            else {
                height = width = 1;
            }

            height *= 64.f;
            width *= 64.f;

            space = 32 - (bStand ? width : height) * 0.5f;

            CImage cImage;
            cImage.Create(64, 64, 32, CImage::createAlphaChannel);

            HDC hdc = cImage.GetDC();
            RECT rc = { 0,0,64,64 };
            SetDCBrushColor(hdc, RGB(255, 0, 255));
            FillRect(hdc, &rc, (HBRUSH)GetStockObject(DC_BRUSH));
            if (bStand)	m_cImageSumnail.TransparentBlt(hdc, int(space), 0, int(width), int(height), RGB(255, 0, 255));
            else		m_cImageSumnail.TransparentBlt(hdc, 0, int(space), int(width), int(height), RGB(255, 0, 255));
            cImage.ReleaseDC();

            ///////////////////////////////////////////////////////

            BITMAPINFO m_bif;
            ZeroMemory(&m_bif, sizeof(BITMAPINFO));

            // 비트맵(DDB) 정보 얻기
            BITMAP bmp;
            GetObject(cImage, sizeof(BITMAP), &bmp);

            // 비트맵(DIB) 정보 설정
            BITMAPINFOHEADER& bmih = m_bif.bmiHeader;
            ZeroMemory(&bmih, sizeof(BITMAPINFOHEADER));
            bmih.biSize = sizeof(BITMAPINFOHEADER);
            bmih.biWidth = bmp.bmWidth;    // 가로
            bmih.biHeight = bmp.bmHeight;  // 세로
            bmih.biPlanes = 1;
            bmih.biBitCount = cImage.GetBPP();          // 픽셀당 비트수(BPP)
            bmih.biCompression = BI_RGB;

            // 비트맵(DIB) 데이터 추출
            // 데이터의 크기를 알아낸다
            HDC hDC = GetDC(NULL);
            GetDIBits(hDC, cImage, 0, bmp.bmHeight, NULL,
                      (LPBITMAPINFO)&bmih, DIB_RGB_COLORS);

            DWORD m_dwImageSize = bmih.biSizeImage;

            // 데이터 저장 공간 확보
            LPBYTE m_bytes = new BYTE[m_dwImageSize];
            GetDIBits(hDC, cImage, 0, bmp.bmHeight, m_bytes, (LPBITMAPINFO)&bmih, DIB_RGB_COLORS);
            ReleaseDC(NULL, hDC);

            size_t cnt = 0;
            for (int y = 0; y < m_bif.bmiHeader.biHeight; y++)  for (int x = 0; x < m_bif.bmiHeader.biWidth; x++)
                {
                    if (!(m_bytes[cnt] == 255 && m_bytes[cnt + 1] == 0 && m_bytes[cnt + 2] == 255))
                        m_bytes[cnt + 3] = 255;
                    cnt += 4;
                }

            LPVOID pNewBytes;
            m_cImage = ::CreateDIBSection(NULL, &m_bif, DIB_RGB_COLORS, &pNewBytes, 0, 0);

            hDC = GetDC(NULL);

            SetDIBits(hDC, m_cImage, 0, m_bif.bmiHeader.biHeight, m_bytes, &m_bif, DIB_RGB_COLORS);

            ReleaseDC(NULL, hDC);


            m_cImageSumnail.Destroy();
            cImage.Destroy();
            delete[] m_bytes;


        }
        else
        {
            SHFILEINFO sfi;
            ZeroMemory(&sfi, sizeof(SHFILEINFO));
            SHGetFileInfo(szPathFileName, 0, &sfi, sizeof(SHFILEINFO),
                          SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SYSICONINDEX | SHGFI_TYPENAME);

            m_hIcon = sfi.hIcon;

        }
    }
    default:
        return false;
    }
    return true;
}
Esempio n. 20
0
//绘画背景
BOOL CServerItmOpaint::OnEraseBkgnd(CDC * pDC)
{
	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

	//建立缓冲
	CImage ImageBuffer;
	ImageBuffer.Create(rcClient.Width(),rcClient.Height(),24);

	//创建 DC
	CDC BufferDC;
	BufferDC.CreateCompatibleDC(pDC);
	BufferDC.SelectObject(ImageBuffer);

	//加载资源
	CImageHandle HandleTitleL(&m_ImageTitleL);
	CImageHandle HandleTitleM(&m_ImageTitleM);
	CImageHandle HandleTitleR(&m_ImageTitleR);

	//绘画背景
	//m_ImageTitleL.BitBlt(BufferDC,0,0);

	//填充中间
	for (INT nXPos=0;nXPos<rcClient.Height()-m_ImageTitleR.GetHeight();nXPos+=m_ImageTitleM.GetHeight())
	{
		m_ImageTitleM.BitBlt(BufferDC,0,nXPos);
	}
	//绘画背景
	m_ImageTitleR.BitBlt(BufferDC,0,rcClient.Height()-m_ImageTitleR.GetHeight());
    
	//设置 DC
	BufferDC.SetTextColor(CR_TEXT);
	BufferDC.SetBkMode(TRANSPARENT);
	BufferDC.SelectObject(CSkinResourceManager::GetDefaultFont());

	//用户信息
	if (m_bShowInfo==true)
	{
		//变量定义
		tagGlobalUserData & GlobalUserInfo=g_GlobalUnits.GetGolbalUserData();

		//用户头像
		g_GlobalUnits.m_UserFaceRes->DrawNormalFace(&BufferDC,10,12,GlobalUserInfo.cbGender,GlobalUserInfo.dwUserID,GlobalUserInfo.dwCustomFaceVer,32,32);

		//构造位置
		TCHAR szBuffer[255]=TEXT("");
		CRect rcAccounts(50,15,rcClient.Width()-20,27);
		CRect rcUnderWrite(50,32,rcClient.Width()-20,44);

		//用户帐号
		_sntprintf(szBuffer,CountArray(szBuffer),TEXT("用户帐号:%s [ %ld ]"),GlobalUserInfo.szAccounts,GlobalUserInfo.dwGameID);
		BufferDC.DrawText(szBuffer,lstrlen(szBuffer),&rcAccounts,DT_VCENTER|DT_WORD_ELLIPSIS|DT_SINGLELINE);

		//会员信息
		LPCTSTR pszMemberOrder[]={TEXT("非会员"),TEXT("红钻会员"),TEXT("蓝钻会员"),TEXT("黄钻会员"),TEXT("紫钻会员")};
		if (GlobalUserInfo.cbMember<CountArray(pszMemberOrder))
		{
			_sntprintf(szBuffer,CountArray(szBuffer),TEXT("会员等级:%s"),pszMemberOrder[GlobalUserInfo.cbMember]);
			BufferDC.DrawText(szBuffer,lstrlen(szBuffer),&rcUnderWrite,DT_VCENTER|DT_WORD_ELLIPSIS|DT_SINGLELINE);
		}
	}
    //绘画界面
	pDC->BitBlt(0,0,rcClient.Width(),rcClient.Height(),&BufferDC,0,0,SRCCOPY);

	//清理资源
	BufferDC.DeleteDC();
	ImageBuffer.Destroy();

	return TRUE;
}
Esempio n. 21
0
//登录消息
bool CPlazaViewItem::OnSocketMainLogon(CMD_Command Command, void * pData, WORD wDataSize)
{
	switch (Command.wSubCmdID)
	{
	case SUB_GP_LOGON_SUCCESS:		//登录成功
		{
			//效验参数
			ASSERT(wDataSize>=sizeof(CMD_GP_LogonSuccess));
			if (wDataSize<sizeof(CMD_GP_LogonSuccess)) return false;

			//保存信息
			tagGlobalUserData & UserData=g_GlobalUnits.GetGolbalUserData();
			CMD_GP_LogonSuccess * pLogonSuccess=(CMD_GP_LogonSuccess *)pData;
			UserData.wFaceID=pLogonSuccess->wFaceID;
			UserData.cbGender=pLogonSuccess->cbGender;
			UserData.cbMember=pLogonSuccess->cbMember;
			UserData.dwUserID=pLogonSuccess->dwUserID;
			UserData.dwGameID=pLogonSuccess->dwGameID;
			UserData.dwExperience=pLogonSuccess->dwExperience;
			UserData.dwCustomFaceVer=pLogonSuccess->dwCustomFaceVer;

			//扩展信息
			void * pDataBuffer=NULL;
			tagDataDescribe DataDescribe;
			CRecvPacketHelper RecvPacket(pLogonSuccess+1,wDataSize-sizeof(CMD_GP_LogonSuccess));
			while (true)
			{
				pDataBuffer=RecvPacket.GetData(DataDescribe);
				if (DataDescribe.wDataDescribe==DTP_NULL) break;
				switch (DataDescribe.wDataDescribe)
				{
				case DTP_USER_ACCOUNTS:		//用户帐户
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szAccounts));
						if (DataDescribe.wDataSize<=sizeof(UserData.szAccounts))
						{
							CopyMemory(UserData.szAccounts,pDataBuffer,DataDescribe.wDataSize);
							UserData.szAccounts[CountArray(UserData.szAccounts)-1]=0;
						}
						break;
					}
				case DTP_USER_PASS:			//用户密码
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szPassWord));
						if (DataDescribe.wDataSize<=sizeof(UserData.szPassWord))
						{
							CopyMemory(UserData.szPassWord,pDataBuffer,DataDescribe.wDataSize);
							UserData.szPassWord[CountArray(UserData.szPassWord)-1]=0;
						}
						break;
					}
				case DTP_UNDER_WRITE:		//个性签名
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szUnderWrite));
						if (DataDescribe.wDataSize<=sizeof(UserData.szUnderWrite))
						{
							CopyMemory(UserData.szUnderWrite,pDataBuffer,DataDescribe.wDataSize);
							UserData.szUnderWrite[CountArray(UserData.szUnderWrite)-1]=0;
						}
						break;
					}
				case DTP_USER_GROUP_NAME:	//社团名字
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szGroupName));
						if (DataDescribe.wDataSize<=sizeof(UserData.szGroupName))
						{
							CopyMemory(UserData.szGroupName,pDataBuffer,DataDescribe.wDataSize);
							UserData.szGroupName[CountArray(UserData.szGroupName)-1]=0;
						}
						break;
					}
				case DTP_STATION_PAGE:		//游戏主站
					{
						ASSERT(pDataBuffer!=NULL);
						if (pDataBuffer!=NULL) 
						{
							g_GlobalUnits.SetStationPage((LPCTSTR)pDataBuffer);
							m_pHtmlBrower->Navigate(g_GlobalUnits.GetStationPage());
						}
						break;
					}
				default: { ASSERT(FALSE); }
				}
			}

			//设置提示
			g_GlobalAttemper.ShowStatusMessage(TEXT("正在读取服务器列表信息..."),this);

			return true;
		}
	case SUB_GP_LOGON_ERROR:		//登录失败
		{
			//效验参数
			CMD_GP_LogonError *pLogonError = (CMD_GP_LogonError *)pData;
			ASSERT(wDataSize>=(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe)));
			if (wDataSize<(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe))) return false;

			//关闭连接
			g_GlobalAttemper.DestroyStatusWnd(this);
			m_ClientSocket->CloseSocket();

			//显示消息
			WORD wDescribeSize=wDataSize-(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe));
			if (wDescribeSize>0)
			{
				pLogonError->szErrorDescribe[wDescribeSize-1]=0;
				ShowMessageBox(pLogonError->szErrorDescribe,MB_ICONINFORMATION);
			}

			//发送登录
			SendLogonMessage();

			return true;
		}
	case SUB_GP_LOGON_FINISH:		//登录完成
		{
			//关闭提示
			g_GlobalAttemper.DestroyStatusWnd(this);

			//展开类型
			INT_PTR nIndex=0;
			CListType * pListType=NULL;
			do
			{
				pListType=g_GlobalUnits.m_ServerListManager.EnumTypeItem(nIndex++);
				if (pListType==NULL) break;
				g_GlobalUnits.m_ServerListManager.ExpandListItem(pListType);
			} while (true);

			//展开列表
			nIndex=0;
			CListInside * pListInside=NULL;
			do
			{
				pListInside=g_GlobalUnits.m_ServerListManager.EnumInsideItem(nIndex++);
				if (pListInside==NULL) break;
				g_GlobalUnits.m_ServerListManager.ExpandListItem(pListInside);
			} while (true);

			//记录信息
			m_bLogonPlaza=true;
			m_DlgLogon.OnLogonSuccess();
			m_pHtmlBrower->EnableBrowser(true);

			//记录信息
			g_GlobalUnits.WriteUserCookie();

			//显示头像
			((CGameFrame*)AfxGetMainWnd())->m_UserInfoView.ShowUserInfo(true);

			//自定义判断
			tagGlobalUserData &GlobalUserData = g_GlobalUnits.GetGolbalUserData();
			if ( GlobalUserData.dwCustomFaceVer!=0)
			{
				//头像名称
				CString strDirName = CString(g_GlobalUnits.GetWorkDirectory()) + TEXT("\\CustomFace");
				CString strFileName;
				strFileName.Format(TEXT("\\%ld_%d.bmp"), GlobalUserData.dwUserID, GlobalUserData.dwCustomFaceVer);

				//读取文件
				CImage FaceImage;
				HRESULT hResult = FaceImage.Load(strDirName + strFileName);
				if (SUCCEEDED(hResult))
				{
					//关闭连接
					m_ClientSocket->CloseSocket();

					FaceImage.Destroy();
				}
				//下载头像
				else
				{
					PostMessage(WM_DOWN_LOAD_FACE, LPARAM(GlobalUserData.dwCustomFaceVer), WPARAM(GlobalUserData.dwUserID));
				}
			}
			else
			{
				//关闭连接
				m_ClientSocket->CloseSocket();
			}

			return true;
		}
	}

	return true;
}
Esempio n. 22
0
bool
EmbedeedFontMan::AddFont(const CString sFontFolder, const CString sFontName){
	CString sDir = sFontFolder;
	if( sDir.GetAt(sDir.GetLength() - 1) != '\\' )
		sDir += _T("\\");

	EmbedeedFont* pFont = new EmbedeedFont();

	// Load characters code map. {{
	BYTE*	lpContent	= NULL;
	int		nSize		= 0;
	if( Path::ReadFileContent(sDir + _T("codes.txt"), lpContent, nSize) && nSize > 0 ){
		CString sContent;
		memcpy(sContent.GetBufferSetLength(nSize), lpContent, nSize);

		CStringArray arrStrings;
		StringHelper::Split(&sContent, _T(";"), arrStrings);

		CString sCharCode;
		for(int i=0; i<arrStrings.GetCount(); i++){
			sCharCode		= arrStrings.GetAt(i);
			int nCharCode	= 0;
			// Hex value
			if( sCharCode.GetAt(0) == '#' )
				nCharCode = StringHelper::HexStringIntoInt(&((TCHAR*)sCharCode.GetBuffer())[1], sCharCode.GetLength() - 1);
			else
				nCharCode = _ttoi(sCharCode.GetBuffer());
			pFont->m_arrCharacters.Add((void*)nCharCode, (void*)i);
			}
		}
	else{
#ifdef _DEBUG
		CString sMsg;
		sMsg.Format(_T("Couldn't find %s"), sDir + _T("codes.txt"));
		AfxMessageBox(sMsg);
#endif
		if( lpContent )
			delete [] lpContent;
		delete pFont;
		return false;
		}
	// }}

	if( lpContent ){
		delete [] lpContent;
		lpContent = NULL;
		}

	CStringArray arrFileNames;
	if( Path::GetFilesByExtention(sDir, _T("*.bmp"), arrFileNames, true) == 0 ){
		delete pFont;
		return false;
		}
	
	for(int i=0; i<arrFileNames.GetCount(); i++){
		CString sName = arrFileNames.GetAt(i);
		CString sName2 = sName;
		CString sFile = sDir + sName;

		if( sName.Left(sFontName.GetLength()) != sFontName )
			continue; // Skip wrong file name.

		sName.Delete	(0, sFontName.GetLength());
		sName.MakeLower	();

		int nIndex = 0;
		EmbedeedFontItemInfo* pInfo = new EmbedeedFontItemInfo();
		pInfo->ZeroInit();

		// Bold
		if( sName.GetAt(nIndex) == 'b' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_BOLD;
			nIndex ++;
			}
		// Underline
		if( sName.GetAt(nIndex) == 'u' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_UNDERLINE;
			nIndex ++;
			}
		// Italic
		if( sName.GetAt(nIndex) == 'i' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_ITALIC;
			nIndex ++;
			}

		// Load characters map image and detect characters left offset and width (in pixels). {{
		CImage* pImage = ImageHelper::LoadImage(sFile, -1, -1, false);
		if( pImage ){
			BITMAP bmImage;
			GetObject(*pImage, sizeof(BITMAP), &bmImage);

			int			nWidthLimit				= bmImage.bmWidth;
			int			nSymbolCt				= 0;
			BYTE*		pBits					= (BYTE*)bmImage.bmBits;
			int			nXOffset				= 0;
			int			nBPP					= bmImage.bmBitsPixel/8;
			int			nSymbolMostLeftOffset	= -1;
			int			nSymbolMostRightOffset	= -1;
			CDWordArray arrSymbolLeftOffsetAndWidth;
			CString		sSymbolStartPointAndWidth;

			int nMaxXOffset = bmImage.bmWidth;
			for(int x=nXOffset; x<nMaxXOffset; x++){
				bool bClearLine = true;
				for(int y=0; y<bmImage.bmHeight; y++){
					BYTE* pLineStartingBits = &pBits[((bmImage.bmHeight - y - 1)*bmImage.bmWidthBytes)];
					BYTE* pPixel			= &pLineStartingBits[x*nBPP];

					// Is pixel visible.
					if( pPixel[0] > 10 ){
						bClearLine = false;
						if( nSymbolMostLeftOffset > -1 )
							nSymbolMostRightOffset = x;
						else
							nSymbolMostLeftOffset = x;
						continue;
						}
		
					pPixel = &pPixel[nBPP];
					}

				if( bClearLine && nSymbolMostLeftOffset > -1 ){
					if( nSymbolMostRightOffset == -1 )
						nSymbolMostRightOffset = nSymbolMostLeftOffset;
					DWORD dwCombineVal = (nSymbolMostLeftOffset << 16) | ((nSymbolMostRightOffset - nSymbolMostLeftOffset + 1)&0xFFFF);
					arrSymbolLeftOffsetAndWidth.Add(dwCombineVal);

#ifdef _DEBUG
					CString sFormat;
					sFormat.Format(_T("%d:%d;"), nSymbolMostLeftOffset, nSymbolMostRightOffset - nSymbolMostLeftOffset + 1);
					sSymbolStartPointAndWidth += sFormat;
#endif
					nSymbolMostLeftOffset	= -1;
					nSymbolMostRightOffset	= -1;
					}
				}

			pInfo->m_imageCharacters.Attach(pImage->Detach());
			delete pImage;

			if( (arrSymbolLeftOffsetAndWidth.GetCount() == pFont->m_arrCharacters.GetCount()) ){
				pInfo->m_pCharPoints = new CPoint[arrSymbolLeftOffsetAndWidth.GetCount()];
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					pInfo->m_pCharPoints[j].x = (int)(dwCombineVal>>16);
					pInfo->m_pCharPoints[j].y = (int)(dwCombineVal&0xFFFF);
					}
				}
			else{
#ifdef _DEBUG
				CBitmap bmImg;
				ImageHelper::CreateDIBBitmap(pInfo->m_imageCharacters.GetBPP(), bmImg, RGB(0, 0, 0), pInfo->m_imageCharacters.GetWidth(),
					pInfo->m_imageCharacters.GetHeight()*2, 0);

				CDC memDC;
				memDC.CreateCompatibleDC(NULL);
				::SelectObject(memDC, bmImg.m_hObject);

				CDC srcDC;
				srcDC.CreateCompatibleDC(NULL);
				::SelectObject(srcDC, pInfo->m_imageCharacters);
				memDC.BitBlt(0, 0, pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight(), &srcDC, 0, 0, SRCCOPY);

				int nHeight = pInfo->m_imageCharacters.GetHeight();
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					int nLeft = (int)(dwCombineVal>>16);
					int nWidth = (int)(dwCombineVal&0xFFFF);

					memDC.FillSolidRect(nLeft, nHeight, nWidth, nHeight, RGB(255, 255, 0));
					}

				DeleteFile(sDir + _T("__") + sName2);
				CImage img;
				img.Attach((HBITMAP)bmImg.Detach());
				img.Save(sDir + _T("__") + sName2);
				img.Destroy();
				
				CString sMsg;
				sMsg.Format(_T("Characters count is not the same for font '%s' item '%s'"), sFontName, sName);
				AfxMessageBox(sMsg);
#endif
				delete pInfo;
				continue;
				}

			pInfo->m_nCharCount = arrSymbolLeftOffsetAndWidth.GetCount();
			}
Esempio n. 23
0
void CChildView::OnSrtpCubemap(){
	// TODO:  在此添加命令处理程序代码
	CWaitCursor wait;
	//int maxY = imgOriginal.GetHeight(), maxX = imgOriginal.GetWidth();
	cube[0].Load(_T("left.png"));
	cube[1].Load(_T("right.png"));
	cube[2].Load(_T("up.png"));
	cube[3].Load(_T("buttom.png"));
	cube[4].Load(_T("front.png"));
	cube[5].Load(_T("back.png"));
	float* center = new float[3];
	float* reflect = new float[3];
	float* res = new float[3];
	CImage tmpimg;
	for (int j = 0; j < 6; j++){
		center[0] = 0.5;
		center[1] = 0.5;
		center[2] = 0.5;
		for (int i = 1; i < 8; i++){
			int newY, newX;
			newY = newX = (int)pow(2.0,(8-i));
			tmpimg.Create(newX, newY, 24, 0);
			float Roughness = (i > 4) ? 0.5f * (i - 4) : i*0.1f;
			for (int x = 0; x < newX; x++){ //列循环
				for (int y = 0; y < newY; y++){ //行循环
					switch (j){
					case 0:
						reflect[0] = 1.0f - (float)x * 1.0f / (float)newX;
						reflect[1] = 0.0f;
						reflect[2] = 1.0f - (float)y * 1.0f / (float)newY;
						break;
					case 1:
						reflect[0] = (float)x * 1.0f / (float)newX;
						reflect[1] = 1.0f;
						reflect[2] = 1.0f - (float)y * 1.0f / (float)newY;
						break;
					case 2:
						reflect[0] = 1.0f - (float)y * 1.0f / (float)newY;
						reflect[1] = (float)x * 1.0f / (float)newX;
						reflect[2] = 1.0f;
						break;
					case 3:
						reflect[0] = (float)y * 1.0f / (float)newY;
						reflect[1] = (float)x * 1.0f / (float)newX;
						reflect[2] = 0.0f;
						break;
					case 4:
						reflect[0] = 1.0f;
						reflect[1] = 1.0f - (float)x * 1.0f / (float)newX;
						reflect[2] = 1.0f - (float)y * 1.0f / (float)newY;
						break;
					case 5:
						reflect[0] = 0.0;
						reflect[1] = (float)x * 1.0f / (float)newX;
						reflect[2] = 1.0f - (float)y * 1.0f / (float)newY;
						break;
					}
					vsub(reflect, center);
					normalize(reflect);
					PrefilterEnvMap(res, Roughness, reflect);
					tmpimg.SetPixelRGB(x, y, (byte)res[0], (byte)res[1], (byte)res[2]);
				}
			}
			CString str,pre;
			pre.Format(_T("%d"), j);
			pre = pre + _T("-");
			str.Format(_T("%d"), i);
			str = pre + str + _T(".bmp");
			HRESULT hResult = tmpimg.Save(str);
			if (FAILED(hResult)) {
				CString fmt;
				fmt.Format(_T("Save image failed:\n%x - %s"), hResult, _com_error(hResult).ErrorMessage());
				::AfxMessageBox(fmt);
				return;
			}
			tmpimg.Destroy();
		}
	}
	delete[] center;
	delete[] reflect;
	delete[] res;
	Invalidate();
	UpdateWindow();
}
Esempio n. 24
-10
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);
}