Ejemplo n.º 1
0
void GPDrawShadowTextSimple( Graphics&gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ )
{
	Gdiplus::Font& gcfont = fontIn;
	Rect rcText = CRect2Rect(rcIn);
	StringFormat fmt;
	fmt.SetAlignment(StringAlignmentCenter);
	fmt.SetTrimming(StringTrimmingEllipsisWord);
	fmt.SetLineAlignment(StringAlignmentCenter);
	StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn;

	GraphicsContainer  gcContainer = gc.BeginContainer();
	gc.SetSmoothingMode(SmoothingModeAntiAlias);
	CComBSTR btrTxtIn(strTxtIn);

	SolidBrush textbrush(ARGB2Color(shadowBrushClrIn));
	RectF rfText = Rect2RectF(rcText);
	if (shadowBrushClrIn != 0)
	{
		rfText.Offset(1.0, 1.0);
		gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush);
	}

	textbrush.SetColor(ARGB2Color(BrushClrIn));
	gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush);
	gc.EndContainer(gcContainer);
}
Ejemplo n.º 2
0
void GPDrawShadowText( Graphics& gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB PenClrIn , ARGB shadowPenClrIn /*= 0xff000000*/, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ )
{
	Gdiplus::Font& gcfont = fontIn;
	FontFamily fmy;
	gcfont.GetFamily(&fmy);
	int nfontStyle  = gcfont.GetStyle();
	REAL dFontSize = gcfont.GetSize();
	Rect rcText = CRect2Rect(rcIn);
	StringFormat fmt;
	fmt.SetAlignment(StringAlignmentCenter);
	fmt.SetTrimming(StringTrimmingEllipsisWord);
	fmt.SetLineAlignment(StringAlignmentCenter);
	StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn;

	GraphicsContainer  gcContainer = gc.BeginContainer();
	gc.SetSmoothingMode(SmoothingModeAntiAlias);
	CComBSTR btrTxtIn(strTxtIn);
	GraphicsPath textPath;
	textPath.AddString(btrTxtIn, -1,  &fmy, nfontStyle, dFontSize, rcText, &fmtUse);

	Matrix mx;
	mx.Translate(nOffXIn, nOffYIn);
	textPath.Transform(&mx);

	Pen textPen(ARGB2Color(shadowPenClrIn), 1);
	SolidBrush textbrush(ARGB2Color(shadowBrushClrIn));
	textPen.SetLineJoin(LineJoinRound);
	if (shadowBrushClrIn != 0)
	{
		gc.FillPath(&textbrush, &textPath);
	}
	if (shadowPenClrIn != 0)
	{
		gc.DrawPath(&textPen, &textPath);
	}



	mx.Invert();
	textPath.Transform(&mx);
	textPen.SetColor(ARGB2Color(PenClrIn));
	textbrush.SetColor(ARGB2Color(BrushClrIn));
	if (BrushClrIn != 0)
	{
		gc.FillPath(&textbrush, &textPath);
	}
	if (PenClrIn != 0)
	{
		gc.DrawPath(&textPen, &textPath);
	}
	gc.EndContainer(gcContainer);
}
Ejemplo n.º 3
0
void GPDrawStretchImage( Graphics& gc, Bitmap* pImage, CRect& rcDes, CRect* prcImgUseIn /*= NULL*/, ENUM_TXBMPSTRETCHTYPE nSTypeIn /*= TXBMP_STRETCH_NONE*/, CRect* prcEdgeIn /*= NULL*/, CRect* prcEdge2In /*= NULL*/ )
{
	if (pImage == NULL || rcDes.IsRectEmpty())
	{
		ASSERT(FALSE);
		return;
	}

	CSize szImage(pImage->GetWidth(), pImage->GetHeight());
	CRect rcImgUse;
	if (prcImgUseIn == NULL)
	{
		rcImgUse = CRect(0,0, szImage.cx, szImage.cy);
	}
	else
	{
		rcImgUse = *prcImgUseIn;
	}

	CRect rcEdgeUse = g_globalInfo.txDrawParam.rcStretchEdge;
	if (prcEdgeIn != NULL)
	{
		rcEdgeUse = *prcEdgeIn;
	}

	GraphicsContainer container = gc.BeginContainer();
	Rect rDes = CRect2Rect(rcDes);
	gc.SetClip(rDes);
	
	if (rcDes.Size() == rcImgUse.Size())
	{
		nSTypeIn = TXBMP_STRETCH_NONE;
	}


	switch(nSTypeIn)
	{
	case TXBMP_STRETCH_NONE:
		{
			gc.DrawImage(pImage, rDes, rcImgUse.left, rcImgUse.top, rcImgUse.Width(), rcImgUse.Height(), UnitPixel);
		}break;
	case TXBMP_STRETCH_LR:
		{
			
		}break;
	case TXBMP_STRETCH_TB:
		{
			ASSERT(FALSE);

		}break;
	case TXBMP_STRETCH_MID_LR:
		{
			CRect rcMid(rcDes);
			rcMid.DeflateRect(rcEdgeUse.left, 0, rcEdgeUse.right, 0);

			//draw left edge
			Rect rLeft = rDes;
			rLeft.Width =rcEdgeUse.left;
			gc.DrawImage(pImage, rLeft, rcImgUse.left, rcImgUse.top, rLeft.Width, rLeft.Height, UnitPixel);

			//draw right edge
			Rect rRight = Rect(rcMid.right, rcDes.top, rcEdgeUse.right, rcDes.bottom);
			CPoint ptImgUse(rcImgUse.right - rcEdgeUse.right, rcImgUse.top);
			gc.DrawImage(pImage, rRight, ptImgUse.x, ptImgUse.y, rRight.Width, rRight.Height, UnitPixel);

			//draw mid
			Rect rMid = CRect2Rect(rcMid);
			CRect rcImgMidUse(rcImgUse);
			rcImgMidUse.DeflateRect(rcEdgeUse.left, 0, rcEdgeUse.right, 0);
			gc.DrawImage(pImage, rMid, rcImgMidUse.left, rcImgMidUse.top, rcImgMidUse.Width(), rcImgMidUse.Height(), UnitPixel);

		}break;
	case TXBMP_STRETCH_MID_TB:
		{
			CRect rcMid(rcDes);
			rcMid.DeflateRect(0, rcEdgeUse.top, 0, rcEdgeUse.bottom);

			//draw top
			Rect rTop(rcDes.left,rcDes.top, rcDes.Width(), rcEdgeUse.top);
			Rect rImgTop(rcImgUse.left, rcImgUse.top, rcImgUse.Width(), rcEdgeUse.top);
			gc.DrawImage(pImage, rTop, rImgTop.X, rImgTop.Y, rImgTop.Width, rImgTop.Height, UnitPixel);
	
			//draw bottom
			Rect rBottom = Rect(rcDes.left, rcMid.bottom, rcDes.Width(), rcEdgeUse.bottom);
			Rect rImgBottom(rcImgUse.left, rcImgUse.bottom - rcEdgeUse.bottom, rcImgUse.Width(), rcEdgeUse.bottom);
			gc.DrawImage(pImage, rBottom, rImgBottom.X, rImgBottom.Y, rImgBottom.Width, rImgBottom.Height, UnitPixel);

			//draw Mid
			Rect rMid = CRect2Rect(rcMid);
			Rect rImgMid(rcImgUse.left, rcImgUse.top + rcEdgeUse.top, rcImgUse.Width(), rcImgUse.Height() - rcEdgeUse.top - rcEdgeUse.bottom);
			gc.DrawImage(pImage, rMid, rImgMid.X, rImgMid.Y, rImgMid.Width, rImgMid.Height, UnitPixel);

		
		}break;
	case TXBMP_STRETCH_MID_LRTB:
		{
			CRect rcMid(rcDes);
			rcMid.DeflateRect(rcEdgeUse);
			CRect rcImgMid(rcImgUse);
			rcImgMid.DeflateRect(rcEdgeUse);
			//left -top corner
			Rect rLeftTop(rcDes.left, rcDes.top, rcEdgeUse.left, rcEdgeUse.top);
			Rect rImgDraw(rcImgUse.left, rcImgUse.top, rcEdgeUse.left, rcEdgeUse.top);
			gc.DrawImage(pImage, rLeftTop, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

			//top
			Rect rTop(rcMid.left, rcDes.top, rcMid.Width(), rcEdgeUse.top);
			rImgDraw = Rect(rcImgMid.left, rcImgUse.top, rcImgMid.Width(), rcEdgeUse.top);

			gc.DrawImage(pImage, rTop, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

			//top - right corner
			Rect rTopRight(rcMid.right, rcDes.top, rcEdgeUse.right, rcEdgeUse.top);
			rImgDraw = Rect(rcImgMid.right, rcImgUse.top, rcEdgeUse.right, rcEdgeUse.top);
			gc.DrawImage(pImage, rTopRight, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

			//right
			Rect rRight(rcMid.right, rcMid.top, rcEdgeUse.right, rcMid.Height());
			rImgDraw = Rect(rcImgMid.right, rcImgMid.top, rcEdgeUse.right, rcImgMid.Height());
			gc.DrawImage(pImage, rRight, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);


			//right-bottom corner
			Rect rRightBottom(rcMid.right, rcMid.bottom, rcEdgeUse.right, rcEdgeUse.bottom);
			rImgDraw = Rect(rcImgMid.right, rcImgMid.bottom, rcEdgeUse.right, rcEdgeUse.bottom);
			gc.DrawImage(pImage, rRightBottom, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

			//bottom
			Rect rBottom(rcMid.left, rcMid.bottom+1, rcMid.Width(), rcEdgeUse.bottom);
			rImgDraw = Rect(rcImgMid.left, rcImgMid.bottom, rcImgMid.Width(), rcEdgeUse.bottom);
			gc.DrawImage(pImage, rBottom, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

			//left-bottom corner
			Rect rLeftBottom(rcDes.left, rcMid.bottom, rcEdgeUse.left, rcEdgeUse.bottom);
			rImgDraw = Rect(rcImgUse.left, rcImgMid.bottom, rcEdgeUse.left, rcEdgeUse.bottom);
			gc.DrawImage(pImage, rLeftBottom, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

			//left
			Rect rLeft(rcDes.left, rcMid.top, rcEdgeUse.left, rcMid.Height());
			rImgDraw = Rect(rcImgUse.left, rcImgMid.top, rcEdgeUse.left, rcImgMid.Height());
			gc.DrawImage(pImage, rLeft, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

			//mid
			Rect rMid = CRect2Rect(rcMid);
			rImgDraw = CRect2Rect(rcImgMid);
			gc.DrawImage(pImage, rMid, rImgDraw.X, rImgDraw.Y, rImgDraw.Width, rImgDraw.Height, UnitPixel);

		}break;
	}

	gc.EndContainer(container);
}
Ejemplo n.º 4
0
bool CGdiPlusImage::DrawImage(CDC* pDC)
{
    //´´½¨ÆÁÄ»
    ASSERT(pDC!=NULL); 
    if ( !pDC ) return false; 

    Bitmap bmp(m_rcDest.Width(), m_rcDest.Height()); 
    Graphics* pGraphics = Graphics::FromImage(&bmp); 
    if ( !pGraphics ) return false;

    GraphicsContainer Containter = pGraphics->BeginContainer();
    pGraphics->SetSmoothingMode(SmoothingModeHighQuality); 

    SolidBrush bgbrush(Color(238, 243, 250));
    pGraphics->FillRectangle(&bgbrush, 0, 0, m_rcDest.Width(), m_rcDest.Height());
    
    if ( m_pImage )
    {
        //»ñÈ¡ÊôÐÔ 
        INT nImageWidth  = m_pImage->GetWidth();
        INT nImageHeight = m_pImage->GetHeight(); 


        float fMin = 1.0F; 
        float fZoomRate = 1.0F; 
        bool bZoomOut = false; 
        int nXSrc = 0;
        int nYSrc = 0; 

        if ( nImageWidth >= m_rcDest.Width() || nImageHeight >= m_rcDest.Height() )
        { 
            float fXRate = 1.0F * m_rcDest.Width() / nImageWidth;
            float fYRate = 1.0F * m_rcDest.Height() / nImageHeight;
            fMin = min(fXRate, fYRate);   
            fZoomRate = max(nImageWidth * 1.0F / m_rcDest.Width(), nImageHeight * 1.0F / m_rcDest.Height()); 
            bZoomOut = true;
        } 


        int nDestWidth  = fMin * nImageWidth;
        int nDestHeight = fMin * nImageHeight;


        //¹¹ÔìλÖÃ
        RectF rcDrawRect;  
        rcDrawRect.X = m_rcDest.left + (m_rcDest.Width() - nDestWidth ) / 2;   
        rcDrawRect.Y = m_rcDest.top + (m_rcDest.Height() - nDestHeight ) / 2; 
        rcDrawRect.Width = nDestWidth;
        rcDrawRect.Height = nDestHeight; 

        Matrix matrix;

        CPoint pt(m_rcDest.Width() / 2, m_rcDest.Height() / 2);
        PointF ptBase((float)pt.x, (float)pt.y);  

        //¾ØÕó±ä»»Òª×¢Òâ˳Ðò£¬ÏÈƽÒÆÔÚËõ·ÅºóÐýת
        matrix.Translate((REAL)m_rcDest.left,(REAL)m_rcDest.top,MatrixOrderAppend);

        //Ëõ·Å
        if ( m_szZoom.cx != 1.0f || m_szZoom.cy != 1.0f )
        {
            ptBase.X += m_szZoom.cx;
            ptBase.Y += m_szZoom.cy;

            matrix.Translate(-ptBase.X,-ptBase.Y,MatrixOrderAppend);
            matrix.Scale(m_szZoom.cx,m_szZoom.cy,MatrixOrderAppend);
            matrix.Translate(ptBase.X,ptBase.Y,MatrixOrderAppend);
        }

        //Ðýת
        if (m_nRotateAngle)
        {
            matrix.RotateAt((REAL)m_nRotateAngle,ptBase,MatrixOrderAppend);
        }

        pGraphics->SetTransform(&matrix);

        //͸Ã÷¾ØÕó
        ColorMatrix Matrix=
        {
            1.0f,0.0f,0.0f,0.0f,0.0f, 
            0.0f,1.0f,0.0f,0.0f,0.0f, 
            0.0f,0.0f,1.0f,0.0f,0.0f,
            0.0f,0.0f,0.0f,m_cbAlphaDepth/255.0f,0.0f, 
            0.0f,0.0f,0.0f,0.0f,1.0f
        };

        //ÉèÖÃÊôÐÔ
        ImageAttributes Attributes; 
        Attributes.SetColorMatrix(&Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); 

        //»æ»­Í¼Ïñ
        pGraphics->DrawImage(m_pImage, rcDrawRect, nXSrc, nYSrc, (REAL)nImageWidth - nXSrc * 2, (REAL)nImageHeight - nYSrc * 2, UnitPixel,&Attributes);  
        pGraphics->ResetTransform();   
        pGraphics->EndContainer(Containter);

    } // if ( m_pImage )
   
    // ´ÓÄڴ濽±´ÖÁÉ豸
    Graphics graphicsreal(pDC->GetSafeHdc()); 
    graphicsreal.DrawImage(&bmp, 0, 0, m_rcDest.Width(), m_rcDest.Height()); 
    delete pGraphics;
    pGraphics = NULL;

    return true;
}