Exemple #1
0
void MyButton::paintEvent(QPaintEvent *e){
	/*绘制按钮的形状*/
	QPainter  g(this);
	int w=width();
	int h=height();
	QPoint pTop(w/2,2);
	QPoint pBottom(w/2,h-2);
	QPoint pLeft(2,h/2);
	QPoint pRight(w-2,h/2);
	QColor cWhite(255,255,255);
	QColor cBlack(  0,  0,  0);
	QBrush bWhite(cWhite);
	QBrush bBlack(cBlack);
	QPen	 penWhite(bWhite,2);
	QPen	 penBlack(bBlack,2);
	
	
	/*白色*/
	g.setPen(penWhite);
	g.drawLine(pTop,pLeft);
	g.drawLine(pTop,pRight);
	/*黑色*/
	g.setPen(penBlack);
	g.drawLine(pBottom,pLeft);
	g.drawLine(pBottom,pRight);
}
Exemple #2
0
void CMainDlg::DrawPhoto()
{
	if (m_BitmapEx.IsValid())
	{

		//CBitmapEx m_PhotoBitmapEx;

		//int tX,tY;
		
		CDC *pDC = m_ctl_photo.GetDC();

		CDC memDC;
		memDC.CreateCompatibleDC(pDC);

		CBitmap bmp;
		bmp.CreateCompatibleBitmap(pDC, m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight());
		memDC.SelectObject(bmp);

		CRect rect(0,0,m_PhotoBitmapEx.GetWidth(),m_PhotoBitmapEx.GetHeight());
		CBrush bBlack(GetSysColor(COLOR_3DFACE));

		memDC.FillRect(&rect, &bBlack);
		m_PhotoBitmapEx.Draw(memDC);

		pDC->FillRect(&m_PhotoRect, &bBlack);

		pDC->SetStretchBltMode(HALFTONE);
		pDC->StretchBlt(0,0,m_PhotoRect.Width(), m_PhotoRect.Height(),
			&memDC, 
			0,0,
			m_CutRect.Width(), m_CutRect.Height(),
			SRCCOPY);

		/*CDC *pDC = m_ctl_photo.GetDC();

		CDC memDC;
		memDC.CreateCompatibleDC(pDC);

		CBitmap bmp;
		bmp.CreateCompatibleBitmap(pDC, m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight());
		memDC.SelectObject(bmp);

		CRect rect(0,0,m_PhotoBitmapEx.GetWidth(),m_PhotoBitmapEx.GetHeight());
		CBrush bBlack(GetSysColor(COLOR_3DFACE));

		memDC.FillRect(&rect, &bBlack);

		m_PhotoBitmapEx.Draw(memDC);

		pDC->FillRect(&m_PhotoRect, &bBlack);

		pDC->SetStretchBltMode(HALFTONE);
		pDC->StretchBlt(0,0,m_PhotoRect.Width(), m_PhotoRect.Height(),
			&memDC, 
			0,0,
			m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight(),
			SRCCOPY);*/

		memDC.DeleteDC();
		ReleaseDC(pDC);
	}
	else
	{
		CDC *pDC = m_ctl_photo.GetDC();
		CBrush bBlack(GetSysColor(COLOR_3DFACE));
		pDC->FillRect(m_PhotoRect,&bBlack);
	}
}
Exemple #3
0
void CMainDlg::DrawPicture()
{
	int tX,tY;
	if (m_SBitmapEx.IsValid())
	{
		m_BitmapEx.Create(m_SBitmapEx.GetWidth(),m_SBitmapEx.GetHeight());
		m_BitmapEx.Draw(0,0,m_SBitmapEx.GetWidth(),m_SBitmapEx.GetHeight(),m_SBitmapEx,0,0);
		m_BitmapEx.Scale(m_nScale,m_nScale);

		CDC *pDC = m_ctl_image.GetDC();

		CDC memDC,memDC1;
		memDC.CreateCompatibleDC(pDC);
		memDC1.CreateCompatibleDC(pDC);

		CBitmap bmp;
		bmp.CreateCompatibleBitmap(pDC, m_BitmapEx.GetWidth(), m_BitmapEx.GetHeight());
		memDC.SelectObject(bmp);
		m_BitmapEx.Draw(memDC);

		CBitmap bmp1;
		bmp1.CreateCompatibleBitmap(pDC, m_ImageRect.Width(), m_ImageRect.Height());
		memDC1.SelectObject(bmp1);

		CPen pen;
		CPen* pOldPen;
		CFont wFont,wFont1;
		CFont *pOldFont;
		CString title;

		//清除背景
		CRgn rgn;
		rgn.CreateRectRgn(0,0,m_ImageRect.Width(),m_ImageRect.Height());
		CBrush bBlack(GetSysColor(COLOR_3DFACE));
		memDC1.FillRgn(&rgn, &bBlack);

		//memDC1.SetStretchBltMode(HALFTONE);
		tX = (m_ImageRect.Width() - m_BitmapEx.GetWidth())/2;
		tY = (m_ImageRect.Height() - m_BitmapEx.GetHeight())/2;

		memDC1.BitBlt(tX,tY,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight(),&memDC,m_pLeft,m_pTop,SRCCOPY);

		pen.CreatePen(PS_SOLID, 1, RGB (255, 0, 0));

		pOldPen = memDC1.SelectObject (&pen);
		memDC1.MoveTo(m_CutRect.left,m_CutRect.top);
		memDC1.LineTo(m_CutRect.right,m_CutRect.top);
		memDC1.LineTo(m_CutRect.right,m_CutRect.bottom);
		memDC1.LineTo(m_CutRect.left,m_CutRect.bottom);
		memDC1.LineTo(m_CutRect.left,m_CutRect.top);
		memDC1.SelectObject (pOldPen);

		/*
		if (m_PicEditStatus)
		{
			//清除背景
			
			if (m_DrawRect.left > 0)
			{
				CRgn rGap1,rGap2,rGap3,rGap4;
				rGap1.CreateRectRgn(0, 0, m_DrawRect.left+10,m_ImageRect.Height());
				rGap2.CreateRectRgn(m_DrawRect.right-10, 0, m_ImageRect.right,m_ImageRect.Height());
				rGap3.CreateRectRgn(0, 0, m_ImageRect.Width(),m_DrawRect.top+10);
				rGap4.CreateRectRgn(0, m_DrawRect.bottom-10, m_ImageRect.Width(),m_ImageRect.bottom);

				rGap1.CombineRgn(&rGap1,&rGap2,RGN_OR);
				rGap1.CombineRgn(&rGap1,&rGap3,RGN_OR);
				rGap1.CombineRgn(&rGap1,&rGap4,RGN_OR);

				CBrush bBlack(GetSysColor(COLOR_3DFACE));
				memDC1.FillRgn(&rGap1, &bBlack);
			}

			memDC1.SetStretchBltMode(HALFTONE);

			if (m_Factor>=0)
			{
				memDC1.StretchBlt(0,0,m_ImageRect.Width(), m_ImageRect.Height(),
					&memDC, 
					(m_BitmapEx.GetWidth())*m_Factor/2,(m_BitmapEx.GetHeight())*m_Factor/2
					,(m_BitmapEx.GetWidth())*(1-m_Factor), (m_BitmapEx.GetHeight())*(1-m_Factor)
					,SRCCOPY);
				m_DrawRect = m_ImageRect;
			}
			else
			{
				memDC1.StretchBlt((m_ImageRect.Width())*(-m_Factor)/2,(m_ImageRect.Height())*(-m_Factor)/2
					,(m_ImageRect.Width())*(1+m_Factor), (m_ImageRect.Height())*(1+m_Factor)
					,&memDC, 
					0,0,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight()
					,SRCCOPY);
				m_DrawRect.left = (m_ImageRect.Width())*(-m_Factor)/2;
				m_DrawRect.top = (m_ImageRect.Height())*(-m_Factor)/2;
				m_DrawRect.right = 
					(m_ImageRect.Width())*(-m_Factor)/2 + (m_ImageRect.Width())*(1+m_Factor) - 1;
				m_DrawRect.bottom = 
					(m_ImageRect.Height())*(-m_Factor)/2 + (m_ImageRect.Height())*(1+m_Factor) - 1; 
			}


			pen.CreatePen(PS_SOLID, 1, RGB (255, 0, 0));
			pOldPen = memDC1.SelectObject (&pen);
			memDC1.MoveTo(m_CutRect.left,m_CutRect.top);
			memDC1.LineTo(m_CutRect.right,m_CutRect.top);
			memDC1.LineTo(m_CutRect.right,m_CutRect.bottom);
			memDC1.LineTo(m_CutRect.left,m_CutRect.bottom);
			memDC1.LineTo(m_CutRect.left,m_CutRect.top);
			memDC1.SelectObject (pOldPen);

			
			title.Format(_T("%d*%d"),
				m_Factor>=0 ? (int)(((double)m_BitmapEx.GetWidth()*(1-m_Factor)) * ((double)m_CutRect.Width()/m_ImageRect.Width())) 
					: (int)(((double)m_BitmapEx.GetWidth()/(1+m_Factor)) * ((double)m_CutRect.Width()/m_ImageRect.Width())),
				m_Factor>=0 ? (int)(((double)m_BitmapEx.GetHeight()*(1-m_Factor)) * ((double)m_CutRect.Height()/m_ImageRect.Height()))  
					: (int)(((double)m_BitmapEx.GetHeight()/(1+m_Factor)) * ((double)m_CutRect.Height()/m_ImageRect.Height())));
			wFont1.CreateFont(12, 0, 0, 0, 0,
				0, 0, 0,
				0, 0, 0, 0,
				VARIABLE_PITCH | FF_SWISS, _T("MS Sans Serif"));
			pOldFont = memDC1.SelectObject(&wFont1);
			memDC1.SetTextColor(RGB(255,0,0));
			memDC1.SetBkMode(TRANSPARENT);
			memDC1.TextOut(m_CutRect.left+2,m_CutRect.top+2, title);
			memDC1.SelectObject(pOldFont);

			
			title.Format(_T("状态:编辑  分辨率:%d*%d"),
				m_Factor>=0 ? (int)((double)m_BitmapEx.GetWidth()*(1-m_Factor)) : (int)((double)m_BitmapEx.GetWidth()/(1+m_Factor)),
				m_Factor>=0 ? (int)((double)m_BitmapEx.GetHeight()*(1-m_Factor))  : (int)((double)m_BitmapEx.GetHeight()/(1+m_Factor)));
			
		}
		else
		{
			memDC1.SetStretchBltMode(HALFTONE);

			memDC1.StretchBlt(0,0,m_ImageRect.Width(), m_ImageRect.Height(),
					&memDC, 
					0,0,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight(),
					SRCCOPY);

			title.Format(_T("状态:显示  分辨率:%d*%d"),m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight());
		}
		*/

		title.Format(_T("缩放:%d:100"),m_nScale);
		
		wFont.CreateFont(12, 0, 0, 0, 0,
			0, 0, 0,
			0, 0, 0, 0,
			VARIABLE_PITCH | FF_SWISS, _T("MS Sans Serif"));
		pOldFont = memDC1.SelectObject(&wFont);
		memDC1.SetTextColor(RGB(255,0,0));
		memDC1.SetBkMode(TRANSPARENT);
		memDC1.TextOut(2,m_ImageRect.bottom-14, title);
		memDC1.SelectObject(pOldFont);

		pDC->BitBlt(0,0,m_ImageRect.Width(), m_ImageRect.Height(),&memDC1,0,0,SRCCOPY);

		memDC.DeleteDC();
		memDC1.DeleteDC();

		ReleaseDC(pDC);

		tX = (m_BitmapEx.GetWidth() - m_CutRect.Width())/2;
		tY = (m_BitmapEx.GetHeight() - m_CutRect.Height())/2;

		m_PhotoBitmapEx.Create(m_CutRect.Width(),m_CutRect.Height());
		m_PhotoBitmapEx.Draw(0,0,m_CutRect.Width(),m_CutRect.Height(),m_BitmapEx,tX + m_pLeft,tY + m_pTop);

		DrawPhoto();

	}else
	{
		CDC *pDC = m_ctl_image.GetDC();
		CBrush bBlack(GetSysColor(COLOR_3DFACE));
		pDC->FillRect(m_ImageRect,&bBlack);

		//m_PhotoBitmapEx.Create(0,0);
		
		//DrawPhoto();
	}
}