Пример #1
2
DLLEXP bool save(WCHAR *fn)
{
	CImage ci;
	ci.Create(g_snap_width,g_snap_height,32,0);
	BitBlt(ci.GetDC(),0,0,g_snap_width,g_snap_height,g_memdc.m_hDC,0,0,SRCCOPY);
	return SUCCEEDED(ci.Save(fn));
}
Пример #2
0
//绘画背景
BOOL CLayeredDialog::OnEraseBkgnd(CDC * pDC)
{
	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

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

	if ( ImageBuffer.IsNull() ) return TRUE;

	//创建 DC
	CImageDC BufferDC(ImageBuffer);
	CDC * pBufferDC=CDC::FromHandle(BufferDC);

	//设置缓冲
	pBufferDC->SetBkMode(TRANSPARENT);

	//绘画背景
	m_ImageBack.DrawImage(pBufferDC,0,0);

	OnDrawClientArea(pBufferDC,rcClient.Width(),rcClient.Height());

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

	return TRUE;
}
Пример #3
0
//绘画头像
VOID CFaceItemControl::DrawFaceOffLine(CDC * pDC, INT nXPos, INT nYPos, INT nWidth, INT nHeight, DWORD dwCustomFace[FACE_CX*FACE_CY])
{
	//创建位图
	CImage ImageCustomFace;
	ImageCustomFace.Create(FACE_CX,FACE_CY,32);

	//获取数据
	INT nImagePitch=ImageCustomFace.GetPitch();
	LPBYTE cbBitCustomFace=(LPBYTE)ImageCustomFace.GetBits();

	//创建区域
	for (INT nYImagePos=0;nYImagePos<FACE_CY;nYImagePos++)
	{
		for (INT nXImagePos=0;nXImagePos<FACE_CX;nXImagePos++)
		{
			//设置颜色
			DWORD dwImageTarget=nYImagePos*nImagePitch+nXImagePos*4L;
			COLORREF crImageTarget=dwCustomFace[nYImagePos*FACE_CX+nXImagePos];

			//提取颜色
			BYTE cbColorR=GetRValue(crImageTarget);
			BYTE cbColorG=GetGValue(crImageTarget);
			BYTE cbColorB=GetBValue(crImageTarget);
			BYTE cbColorGray=(BYTE)(cbColorR*0.30+cbColorG*0.59+cbColorB*0.11);

			//设置颜色
			*(COLORREF *)(cbBitCustomFace+dwImageTarget)=RGB(cbColorGray,cbColorGray,cbColorGray);
		}
	}

	//绘画界面
	ImageCustomFace.Draw(pDC->m_hDC,nXPos,nYPos,nWidth,nHeight);

	return;
}
Пример #4
0
//绘画头像
VOID CFaceItemControl::DrawFaceNormal(CDC * pDC, INT nXPos, INT nYPos, INT nWidth, INT nHeight, DWORD dwCustomFace[FACE_CX*FACE_CY])
{
	//创建位图
	CImage ImageCustomFace;
	ImageCustomFace.Create(FACE_CX,FACE_CY,32);

	//获取数据
	INT nImagePitch=ImageCustomFace.GetPitch();
	LPBYTE cbBitCustomFace=(LPBYTE)ImageCustomFace.GetBits();

	//创建区域
	for (INT nYImagePos=0;nYImagePos<FACE_CY;nYImagePos++)
	{
		for (INT nXImagePos=0;nXImagePos<FACE_CX;nXImagePos++)
		{
			//设置颜色
			DWORD dwImageTarget=nYImagePos*nImagePitch+nXImagePos*4L;
			*(COLORREF *)(cbBitCustomFace+dwImageTarget)=dwCustomFace[nYImagePos*FACE_CX+nXImagePos];
		}
	}

	//绘画界面
	ImageCustomFace.Draw(pDC->m_hDC,nXPos,nYPos,nWidth,nHeight);

	return;
}
//处理图片
bool CRichEditMessage::LoadRichEditImage(HINSTANCE hInstance, UINT uResourceID, CDataObject&ImageDataObject)
{
	//加载图片
	CBitImage ImageFile;
	ImageFile.LoadFromResource(hInstance,uResourceID);

	//失败判断
	if (ImageFile.IsNull()==true)
	{
		ASSERT(FALSE);
		return false;
	}

	//创建表情
	CImage ImageRichEdit;
	ImageRichEdit.Create(ImageFile.GetWidth(),ImageFile.GetHeight(),32);

	//绘画表情
	CDC * pDC=CDC::FromHandle(ImageRichEdit.GetDC());
	pDC->FillSolidRect(0,0,ImageFile.GetWidth(),ImageFile.GetHeight(),m_crFillColor);
	ImageFile.TransDrawImage(pDC,0,0,RGB(255,0,255));

	//设置图片
	ImageRichEdit.ReleaseDC();
	ImageDataObject.SetImage(ImageRichEdit.Detach());

	return true;
}
Пример #6
0
void CBaseDialog::DrawClientArea( CDC*pDC,int nWidth,int nHeight )
{
	//创建缓冲
	CImage ImageBuffer;
	ImageBuffer.Create(nWidth,nHeight,32);

	//变量定义
	CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC());

	pBufferDC->FillSolidRect(1,0,nWidth-2,nHeight,RGB(234,238,244));

	if ( CHECK_IMAGE(m_pImageBack) )
	{
		m_pImageBack->DrawImage(pBufferDC,0,0,nWidth-1,nHeight-1);
	}
 
	if ( CHECK_IMAGE(m_pShadow) )
	{
		m_pShadow->DrawImage(pBufferDC,0,0,nWidth-1,nHeight-1);
	}

	DrawView(pBufferDC,nWidth-2,nHeight);

	pBufferDC->SetBkMode(TRANSPARENT);
	pBufferDC->SelectObject(RenderEngine->GetDeaultFont());
	pBufferDC->SetTextColor(RGB(255,255,255));

	//绘画界面
	pDC->BitBlt(0,0,nWidth,nHeight,pBufferDC,0,0,SRCCOPY);

	//清理资源
	ImageBuffer.ReleaseDC();
}
Пример #7
0
//绘画头像
VOID CFaceItemSelectWnd::DrawFaceItem(CDC * pDC, WORD wIndex, INT nXPos, INT nYPos, bool bHover)
{
	//获取对象
	ASSERT(CFaceItemControl::GetInstance()!=NULL);
	IFaceItemControl * pIFaceItemControl=CFaceItemControl::GetInstance();

	//创建缓冲
	CImage ImageBuffer;
	ImageBuffer.Create(FRAME_WIDTH+FACE_CX,FRAME_HEIGHT+FACE_CY,32);

	//绘画背景
	CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC());
	pBufferDC->FillSolidRect(0,0,FRAME_WIDTH+FACE_CX,FRAME_HEIGHT+FACE_CY,CR_BACK_FRAME);

	//绘画框架
	BYTE cbFrameKind=(bHover==true)?ITEM_FRAME_HOVER:ITEM_FRAME_NORMAL;
	pIFaceItemControl->DrawFaceItemFrame(pBufferDC,FRAME_WIDTH/2,FRAME_HEIGHT/2,cbFrameKind);

	//绘画头像
	pIFaceItemControl->DrawFaceNormal(pBufferDC,FRAME_WIDTH/2,FRAME_HEIGHT/2,wIndex);

	//绘画界面
	pDC->BitBlt(nXPos,nYPos,FRAME_WIDTH+FACE_CX,FRAME_HEIGHT+FACE_CY,pBufferDC,0,0,SRCCOPY);

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

	return;
}
Пример #8
0
//输入解释
void CExpressionItem::InitExpressItem(LPCTSTR pszChineseName, LPCTSTR pszTrancelate, UINT uIDResource)
{
	//设置变量
	m_uImageID=uIDResource;
	lstrcpyn(m_szTrancelate,pszTrancelate,CountArray(m_szTrancelate));
	lstrcpyn(m_szChineseName,pszChineseName,CountArray(m_szChineseName));
	m_wTranceLength=lstrlen(m_szTrancelate);

	//加载图片
	CSkinImage ImageFile;
	ImageFile.LoadFromResource(GetModuleHandle(CLIENT_SHARE_DLL_NAME),uIDResource);

	//创建表情
	CImage ImageExpression;
	ASSERT(ImageFile.GetWidth()==EP_PIC_WHIDE);
	ASSERT(ImageFile.GetHeight()==EP_PIC_HIGHT);
	ImageExpression.Create(EP_PIC_WHIDE,EP_PIC_HIGHT,32);

	//绘画表情
	CDC * pDC=CDC::FromHandle(ImageExpression.GetDC());
	pDC->FillSolidRect(0,0,EP_PIC_WHIDE,EP_PIC_HIGHT,COLOR_CHAR_BK);
	ImageFile.AlphaDrawImage(pDC,0,0,RGB(255,0,255));

	//设置图片
	ImageExpression.ReleaseDC();
	m_ImageDataObject.SetImage(ImageExpression.Detach());

	return;
};
Пример #9
0
void CChartCtrl::SaveAsImage(const TChartString& strFilename, 
							 const CRect& rect,
							 int nBPP,
							 REFGUID guidFileType)
{
	//AFX_MANAGE_STATE(AfxGetStaticModuleState()); 

	CImage chartImage;
	CRect chartRect = rect;
	if (chartRect.IsRectEmpty())
	{
		GetClientRect(&chartRect);
	}
    
	chartImage.Create(chartRect.Width(), chartRect.Height(), nBPP);
	CDC newDC;
	newDC.Attach(chartImage.GetDC());

	DrawBackground(&newDC, chartRect);
	chartRect.DeflateRect(3,3);
	DrawChart(&newDC, chartRect);

	newDC.Detach();
	chartImage.Save(strFilename.c_str(), guidFileType);
	chartImage.ReleaseDC();
}
Пример #10
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: 在此添加命令处理程序代码
}
Пример #11
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();
}
Пример #12
0
//确定函数
VOID CDlgCustomFace::OnOK()
{
	//连接判断
	bool bConnect=false;

	//系统模式
	if (m_cbMode==MM_SYSTEM)
	{
		CGlobalUserInfo * pGlobalUserInfo=CGlobalUserInfo::GetInstance();
		bConnect=(pGlobalUserInfo->GetGlobalUserData()->wFaceID!=m_wFaceID);
	}

	//自定模式
	if (m_cbMode==MM_CUSTOM)
	{
		//创建缓冲
		CImage ImageCustomFace;
		ImageCustomFace.Create(FACE_CX,FACE_CY,32);

		//创建 DC
		CImageDC BufferDC(ImageCustomFace);
		m_FaceItemCustomWnd.DrawEditImage(CDC::FromHandle(BufferDC),0,0,FACE_CX,FACE_CY);

		//获取数据
		INT nImagePitch=ImageCustomFace.GetPitch();
		LPBYTE cbBitCustomFace=(LPBYTE)ImageCustomFace.GetBits();

		//创建区域
		for (INT nYImagePos=0;nYImagePos<FACE_CY;nYImagePos++)
		{
			for (INT nXImagePos=0;nXImagePos<FACE_CX;nXImagePos++)
			{
				//设置颜色
				DWORD dwImageTarget=nYImagePos*nImagePitch+nXImagePos*4L;
				m_CustomFaceInfo.dwCustomFace[nYImagePos*FACE_CX+nXImagePos]=*(COLORREF *)(cbBitCustomFace+dwImageTarget);
			}
		}

		//设置变量
		bConnect=true;
		m_CustomFaceInfo.dwDataSize=sizeof(m_CustomFaceInfo);
	}

	//激活任务
	if (bConnect==true)
	{
		//控件控制
		EnableControl(false);

		//激活任务
		m_MissionManager.AvtiveMissionItem(this,false);

		return;
	}

	__super::OnOK();
}
Пример #13
0
//绘制背景
BOOL CImageEditorControl::OnEraseBkgnd(CDC * pDC)
{
	//获取大小
	CRect rcClient;
	GetClientRect(&rcClient);

	//创建缓冲
	CImage ImageBuffer;
	ImageBuffer.Create(rcClient.Width(),rcClient.Height(),32);

	//变量定义
	HDC hBufferDC=ImageBuffer.GetDC();
	CDC * pBufferDC=CDC::FromHandle(hBufferDC);

	//绘画背景
	pBufferDC->FillSolidRect(&rcClient,RGB(255,255,255));

	//绘画图像
	if (m_ImageSource.IsNull()==false)
	{
		//加载图片
		CPngImage ImageEditGray;
		ImageEditGray.LoadImage(GetModuleHandle(AVATAR_CONTROL_DLL_NAME),TEXT("FACE_EDIT_GRAY"));

		//设置环境
		pBufferDC->SetStretchBltMode(HALFTONE);

		//绘画图片
		m_ImageSource.StretchBlt(hBufferDC,(rcClient.Width()-m_SizeTarget.cx)/2,(rcClient.Height()-m_SizeTarget.cy)/2,
			m_SizeTarget.cx,m_SizeTarget.cy,0,0,m_SizeSource.cx,m_SizeSource.cy);

		//绘画蒙图
		ImageEditGray.DrawImage(pBufferDC,(rcClient.Width()-m_SizeTarget.cx)/2,(rcClient.Height()-m_SizeTarget.cy)/2,
			m_SizeTarget.cx,m_SizeTarget.cy,0,0,ImageEditGray.GetWidth(),ImageEditGray.GetHeight());

		//绘画图片
		m_ImageSource.StretchBlt(hBufferDC,m_rcImageSelect.left,m_rcImageSelect.top,m_rcImageSelect.Width(),m_rcImageSelect.Height(),
			m_SizeSource.cx*(m_rcImageSelect.left-(rcClient.Width()-m_SizeTarget.cx)/2)/m_SizeTarget.cx,
			m_SizeSource.cy*(m_rcImageSelect.top-(rcClient.Height()-m_SizeTarget.cy)/2)/m_SizeTarget.cy,
			m_SizeSource.cx*m_rcImageSelect.Width()/m_SizeTarget.cx,m_SizeSource.cy*m_rcImageSelect.Height()/m_SizeTarget.cy);

		//绘画框架
		DrawLineFrame(pBufferDC);
	}

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

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

	return TRUE;
}
Пример #14
0
LPIMAGE CreateImage(
    LPSTR       szName,         // image filename
    LPFRAME     lpFrame,        // frame - if NULL, use lpObject
    LPOBJECT    lpObject,       // object list pointer - if NULL, use lpFrame
    LPCMDLIST   lpCmdList,      // command processing list
    ITEMID      FileType,       // image file type - IDN_TIFF, etc.
    ITEMID      DataType,       // image data type - IDC_SAVECT, etc.
    int         DocumentType,   // bitwise document type, normal, fastbits, lowres
    LPSTR       ImageName)      // name used for internal use only
/***********************************************************************/
{
	CImage *pNewImage;
	BOOL fSuccess;

	ASSERT((lpFrame != NULL) || (lpObject != NULL));

	TRY
	{
		pNewImage = new CImage(DataType, szName, lpCmdList, FileType, DocumentType, ImageName);
	}
	CATCH_ALL(e)
	{
		Message(IDS_EMEMALLOC);
		return(NULL);
	}
	END_CATCH_ALL

	if (lpObject)
 		fSuccess = pNewImage->Create(lpObject);
	else
 		fSuccess = pNewImage->Create(lpFrame);

	if (!fSuccess)
	{
	 	delete pNewImage;
		pNewImage = NULL;
	}

	return( pNewImage );
}
Пример #15
0
void ExportTexturePage(int nPage)
{
	//
	// This is where texture is converted from paletted BGR5A1 to BGRA8
	// Also saving to LEVEL_texture/PAGE_*
	//

	texdata_t* page = &g_pageDatas[nPage];

	if(!page->data)
		return;		// NO DATA

	CImage img;
	uint* color_data = (uint*)img.Create(FORMAT_RGBA8, 256,256,1,1);

	memset(color_data, 0, img.GetSliceSize());

	int clut = max(page->numPalettes, g_texPages[nPage].numDetails);

	for(int i = 0; i < g_texPages[nPage].numDetails; i++, clut++)
	{
		int ox = g_texPages[nPage].details[i].x;
		int oy = g_texPages[nPage].details[i].y;
		int w = g_texPages[nPage].details[i].w;
		int h = g_texPages[nPage].details[i].h;

		char* name = g_textureNamesData + g_texPages[nPage].details[i].texNameOffset;
		
		/*
		Msg("Texture detail %d (%s) [%d %d %d %d]\n", i,name,
														g_texPages[nPage].details[i].x,
														g_texPages[nPage].details[i].y,
														g_texPages[nPage].details[i].w,
														g_texPages[nPage].details[i].h);
		*/
		for(int y = oy; y < oy+h; y++)
		{
			for(int x = ox; x < ox+w; x++)
			{
				ubyte clindex = page->data[y*256 + x];

				TVec4D<ubyte> color = bgr5a1_ToRGBA8( page->clut[i].colors[clindex] );

				color_data[y*256 + x] = *(uint*)(&color);
			}
		}
	}

	Msg("Writing texture %s/PAGE_%d.tga\n", g_levname_texdir.c_str(), nPage);

	img.SaveTGA(varargs("%s/PAGE_%d.tga", g_levname_texdir.c_str(), nPage));
}
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();


}
Пример #17
0
int savepng(TCHAR *szFilename)
{
    HDC hdcSrc = GetDC(NULL);
    int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
    int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
    int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
    CImage image;
    image.Create(nWidth, nHeight, nBitPerPixel);
    BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY);
    ReleaseDC(NULL, hdcSrc);
    image.ReleaseDC();
    image.Save(szFilename, Gdiplus::ImageFormatPNG);//ImageFormatJPEG
    return 0;
}
CImage * CDrawableWidget::GetBlankImage(double lfSizeScale, bool bHasAlpha)
{
	CImage * pResult = NULL;
	pResult = new CImage;

	GetClientRect(&m_rect);
	int nWidth = static_cast<int>(lfSizeScale*m_rect.right);
	int nHeight = static_cast<int>(lfSizeScale*m_rect.bottom);
	
	
	pResult->Create(nWidth, nHeight, 24+((!!bHasAlpha)<<3));

	return pResult;
}
///<summary>
///	OpenCVのimageデータであるMat型データをMFCのCImage型オブジェクトに変換してダイアログ表示(作成中)
///</summary>
void CImageProcessor::ShowPictureDlg(cv::Mat cvImg)
{
	cv::Size size = cvImg.size();

	// 上下反転
	cv::flip(cvImg, cvImg, 0);

	BITMAPINFO bmpInfo;
	bmpInfo.bmiHeader.biBitCount = cvImg.channels() * 8;
	bmpInfo.bmiHeader.biWidth = size.width;
	bmpInfo.bmiHeader.biHeight = size.height;
	bmpInfo.bmiHeader.biPlanes = 1;
	bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmpInfo.bmiHeader.biCompression = BI_RGB;
	bmpInfo.bmiHeader.biClrImportant =
		bmpInfo.bmiHeader.biClrUsed =
		bmpInfo.bmiHeader.biSizeImage =
		bmpInfo.bmiHeader.biXPelsPerMeter =
		bmpInfo.bmiHeader.biYPelsPerMeter = 0;

	CImage* image = new CImage;
	image->Create(bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, bmpInfo.bmiHeader.biBitCount);
	//HDC hdc = image->GetDC();

	StretchDIBits(
		image->GetDC(), //HDC
		0, 0, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight,//コピー先サイズ
		0, 0, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight,//コピー元サイズ
		cvImg.data, &bmpInfo, DIB_RGB_COLORS, SRCCOPY);

	//http://chichimotsu.hateblo.jp/entry/20121130/1354265478
	//HBITMAP hbmp = CreateCompatibleBitmap(hdc, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight);
	//SetDIBits(hdc, hbmp, 0, bmpInfo.bmiHeader.biHeight, cvImg.data, &bmpInfo, DIB_RGB_COLORS);
	//HDC hdc2 = CreateCompatibleDC(hdc);
	//SelectObject(hdc2, hbmp);
	//BitBlt(hdc, 0, 0, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, hdc2, 0, 0, SRCCOPY);
	//DeleteDC(hdc2);
	//DeleteObject(hbmp);

	CPictureDlg dlg(image);
	dlg.DoModal();

	if (image)
	{
		image->ReleaseDC();
		delete image;
		image = NULL;
	}
}
Пример #20
0
BOOL CUIDesignerView::SaveSkinImage(LPCTSTR pstrPathName)
{
	CImage image;
	CWindowUI* pForm = m_LayoutManager.GetForm();
	ASSERT(pForm);

	CSize szForm = pForm->GetInitSize();
	CRect rcPaint(0,0,szForm.cx,szForm.cy);
	image.Create(szForm.cx, szForm.cy, 32);
	pForm->DoPaint(image.GetDC(), rcPaint);
	BOOL bRet = image.Save(pstrPathName, Gdiplus::ImageFormatJPEG);

	image.ReleaseDC();
	return bRet;
}
Пример #21
0
float CTools::DrawToCDC(IplImage* img,CDC* pDC)
{
	CRect rect;
	CImage bkgound;
	float ratio;
	BITMAPINFO bmi;
	BITMAPINFOHEADER* bmih = &(bmi.bmiHeader);
	memset( bmih, 0, sizeof(*bmih));
	IplImage* pImg = cvCreateImage(cvSize(img->width,img->height),IPL_DEPTH_8U,3);

	if ((img->nChannels * img->depth) == 8)
	{
		cvCvtColor(img,pImg,CV_GRAY2RGB);
	}

	if ((img->nChannels * img->depth) == 24)
	{
		cvCopy(img,pImg);
	}
	if ((img->nChannels * img->depth) > 24)
	{
		AfxMessageBox(L"ÇëÊäÈë8BPP»ò24BPPµÄͼÏñ£¡");
		return 0;
	}

	bmih->biSize   = sizeof(BITMAPINFOHEADER);
	bmih->biWidth  = pImg->width;
	bmih->biHeight = -abs(pImg->height);
	bmih->biPlanes = 1;
	bmih->biBitCount = 24;
	bmih->biCompression = BI_RGB;

	pDC->GetWindow()->GetWindowRect(&rect);
	bkgound.Create(rect.Width(),rect.Height(),24);
	if((float)rect.Height()/(pImg->height) > (float)rect.Width()/(pImg->width))
	{
		ratio = (float)rect.Width()/(pImg->width);
		bkgound.Draw(pDC->GetSafeHdc(),0,(int)((pImg->height)*ratio),rect.Width(),rect.Height() - (int)((pImg->height)*ratio));
	}
	else{
		ratio = (float)rect.Height()/(pImg->height);
		bkgound.Draw(pDC->GetSafeHdc(),(int)((pImg->width)*ratio),0,rect.Width() - (int)((pImg->width)*ratio),rect.Height());
	}	
	pDC->SetStretchBltMode(HALFTONE);
	::StretchDIBits(pDC->GetSafeHdc(),0,0,(int)((pImg->width)*ratio),(int)((pImg->height)*ratio),0,0,pImg->width,pImg->height,pImg->imageData,&bmi,DIB_RGB_COLORS,SRCCOPY);
	cvReleaseImage(&pImg);
	return ratio;
} 
Пример #22
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;
}
Пример #23
0
//设置区域
VOID CLayeredWindow::InitLayeredArea(CImageEx & Image, BYTE cbAlpha, CRect & rcUnLayered, CPoint & PointRound, bool bUnLayeredChild)
{
	//创建缓冲
	CImage ImageBuffer;
	ImageBuffer.Create(Image.GetWidth(),Image.GetHeight(),32);

	//绘画界面
	CImageDC ImageDC(ImageBuffer);
	CDC * pBufferDC=CDC::FromHandle(ImageDC);

	//绘画界面
	ASSERT(pBufferDC!=NULL);
	if (pBufferDC!=NULL) Image.DrawImage(pBufferDC,0,0);

	//创建分层
	InitLayeredArea(pBufferDC,cbAlpha,rcUnLayered,PointRound,bUnLayeredChild);

	return;
}
Пример #24
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];  
                }             
            }  
        }     
    }  

}
///<summary>
///	LPCOLORREFの画像データ配列をMFCのCImage型オブジェクトに変換してダイアログ表示
///</summary>
void CImageProcessor::ShowPictureDlg(LPCOLORREF pixelData, BITMAPINFO* bmpInfo)
{
	CImage* image = new CImage;
	image->Create(bmpInfo->bmiHeader.biWidth, bmpInfo->bmiHeader.biHeight, bmpInfo->bmiHeader.biBitCount);

	StretchDIBits(
		image->GetDC(), //HDC
		0, 0, bmpInfo->bmiHeader.biWidth, bmpInfo->bmiHeader.biHeight, //コピー先サイズ
		0, 0, bmpInfo->bmiHeader.biWidth, bmpInfo->bmiHeader.biHeight, //コピー元サイズ
		pixelData, bmpInfo, DIB_RGB_COLORS, SRCCOPY);

	CPictureDlg dlg(image);
	dlg.DoModal();

	if (image)
	{
		image->ReleaseDC();
		delete image;
		image = NULL;
	}
}
Пример #27
0
void TestCommand::Func2()
{
	CImage saveimg;
	saveimg.Create(img_->GetWidth()/2,img_->GetHeight()/2,8);
	int steps=m_min(img_->GetWidth()/2,img_->GetHeight()/2);
	BYTE *psrc=(BYTE *)img_->GetImage()->GetBits();
	int nrowsrc=img_->GetImage()->GetPitch();
	BYTE *pdes=(BYTE *)saveimg.GetBits();
	int nrowdes=saveimg.GetPitch();
	for(int xi=0;xi<steps;xi++)
		for(int yi=0;yi<steps;yi++)
		{
			pdes[yi*nrowdes+xi]=(psrc[(yi*2)*nrowsrc+(xi*2)*3]+psrc[(yi*2)*nrowsrc+(xi*2)*3+1]+psrc[(yi*2)*nrowsrc+(xi*2)*3+2]
			                             +psrc[(yi*2)*nrowsrc+(2*xi+1)*3]+psrc[(yi*2)*nrowsrc+(2*xi+1)*3+1]+psrc[(yi*2)*nrowsrc+(2*xi+1)*3+2]
										 +psrc[(yi*2+1)*nrowsrc+(2*xi)*3]+psrc[(yi*2+1)*nrowsrc+(2*xi)*3+1]+psrc[(yi*2+1)*nrowsrc+(2*xi)*3+2]
										 +psrc[(yi*2+1)*nrowsrc+(2*xi+1)*3]+psrc[(yi*2+1)*nrowsrc+(2*xi+1)*3]+psrc[(yi*2+1)*nrowsrc+(2*xi+1)*3])/12;

		}
		saveimg.SetColorTable(0,255,ImageYH::GetColorTable());
		saveimg.Save("d:\\testImg\\lena256.bmp");
}
Пример #28
0
LRESULT CozyCaptureWindow::OnLeftButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    if (m_ThisStatus == CaptureStatus::S_None)
    {
        m_IsMoved       = false;
        m_ThisStatus    = CaptureStatus::S_Selecting;
        m_BeginPoint    = POINT{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
    }
    else if (m_ThisStatus == CaptureStatus::S_Selected)
    {
        RECT ActRect;
        Point2Rect(m_BeginPoint, m_CurrPoint, &ActRect);

        CImage OutputImg;
        OutputImg.Create(ActRect.right - ActRect.left, ActRect.bottom - ActRect.top, m_CaptureImg.GetBPP());

        {
            CImageDC outputDc(OutputImg);
            m_CaptureImg.BitBlt(outputDc, 0, 0, ActRect.right - ActRect.left, ActRect.bottom - ActRect.top, ActRect.left, ActRect.top);
        }
        if (m_IsSaveToFile)
        {
            if (SendImageToFile(OutputImg))
            {
                *m_lpResultState |= RET_FILE;
            }
        }
        if (m_IsSaveToClipboard)
        {
            if (SendImageToClipboard(OutputImg))
            {
                *m_lpResultState |= RET_CLIP;
            }
        }
        SetWindowPos(HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);
        Exit();
    }
    return 0;
}
Пример #29
0
/*!
 @brief イメージの取得

 @param [in]    pSelectItem     選択データ
 @param [out]   bitmap          イメージ
 */
BOOL CImageFontDlg::GetBitmapImage(LPVOID pSelectItem, CImage &bitmap)
{
	CRect rect;
	GetClientRect(&rect);

	bitmap.Create(rect.Width(), rect.Height(), 32);

	HDC hDC = bitmap.GetDC();
	Gdiplus::Graphics graphics(hDC);
	graphics.Clear((Gdiplus::ARGB)Gdiplus::Color::White);

	CString strMessage;
	strMessage = _T("1234567890\n");
	strMessage += _T("abcdefghijklmnopqrstuvwxyz\n");
	strMessage += _T("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
	strMessage += _T("あいおえおかきくけこさしすせそたちつてとなにぬねの\n");
	strMessage += _T("はひふへほまみむめもやゆよらりるれろわをん\n");

	LOGFONT *pLogfont = (LOGFONT *) pSelectItem;
	Gdiplus::Font font(hDC, pLogfont);

	Gdiplus::RectF drawLayout(0, 0, (Gdiplus::REAL)rect.Width(), (Gdiplus::REAL)rect.Height());

	Gdiplus::StringFormat stringFormat;
	stringFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
	stringFormat.SetTrimming(Gdiplus::StringTrimmingNone);

	Gdiplus::SolidBrush brush((Gdiplus::ARGB)Gdiplus::Color::Black);

	graphics.SetTextRenderingHint((Gdiplus::TextRenderingHint) (GetSpaceKeyDownCount() % (int)Gdiplus::TextRenderingHintClearTypeGridFit));
	graphics.DrawString(strMessage, -1, &font, drawLayout, &stringFormat,&brush);


	bitmap.ReleaseDC();

	return TRUE;
}
Пример #30
0
void Window::updateText()
{
	CRect rectClient;
    GetClientRect(hWnd, &rectClient);

    CImage img;
    if(img.Create(rectClient.Width(), rectClient.Height(), 32, CImage::createAlphaChannel))
    {
        drawText(img.GetDC());
		img.ReleaseDC();

        POINT pt = {0, 0};
        SIZE size = {rectClient.Width(), rectClient.Height()};

        BLENDFUNCTION bf = {0};
        bf.BlendOp = AC_SRC_OVER; 
        bf.BlendFlags = 0; 
        bf.AlphaFormat = AC_SRC_ALPHA;
        bf.SourceConstantAlpha = 255;

        UpdateLayeredWindow(hWnd, 0, 0, &size, img.GetDC(), &pt, 0, &bf, ULW_ALPHA);
        img.ReleaseDC();
	}
}