Example #1
0
Gdiplus::Bitmap* CSkinUnitODL::CreateImageData( INT nGroutX, INT nGroutY, INT nSrcWidth, INT nSrcHeight, Gdiplus::Color clBackground, CString strPicPath )
{
	//定义目标图片:代表宽度、高度,水泥槽宽度
	Gdiplus::Bitmap *img=new Gdiplus::Bitmap(nSrcWidth + nGroutX, nSrcHeight + nGroutY);
	//计算点的最大最小位置
	Gdiplus::Bitmap bmp(strPicPath);
	Gdiplus::Graphics buffer(img);//Gaphics对象引用内存画布   
	buffer.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);//SmoothingModeAntiAlias);
	buffer.ResetTransform();
	buffer.Clear(clBackground);
	{
		Gdiplus::ImageAttributes attImage;
		attImage.SetWrapMode(Gdiplus::WrapMode::WrapModeTile);

		Gdiplus::Rect rtDraw(nGroutX/2, nGroutY/2, nSrcWidth, nSrcHeight);
		//图片原始尺寸在bmp内,画到 x,y点, 需要原始图片的位置是 srcX, srcY, 目标图形区域大小是 srcWidth, srcHeight
		buffer.DrawImage(&bmp, rtDraw, 0, 0, bmp.GetWidth(), bmp.GetHeight(), Gdiplus::Unit::UnitPixel, &attImage);
	}

	return img;
}
// ---------------------------------------------------------------------------
// draw short line pixel by pixel.
// ---------------------------------------------------------------------------
//
void CPeninputPenTraceDecorator::DrawShortSegment( TDrawLineParams* aParams )
{
    TInt32 RPF2;   // squares of outer circle radius
    TInt32 RMF2;   // squares of inner circle radius
    TInt32 LX;     // left border of circle
    TInt32 RX;     // right border of circle
    TInt32 LY;     // top border of circle
    TInt32 RY;     // bottom border of circle
    TInt32 SqY;    // squares of Y
    TInt32 SqDist; // squared distance from center for one pixel
    TInt32 RPMF2;  // diameter of circle
    TInt32 nFact;

    TInt32 x, y;
    TInt32 d = aParams->currd;

    TInt32 color = aParams->color;

    d = ( d < 12 ) ? 12 : d;
    RPF2 = ( d + 8 );
    RMF2 = ( d - 8 );
    RMF2 = ( RMF2 < 8 ) ? 8 : RMF2;

    // Determine bounds
    LX = (TInt32)( (aParams->currx - RPF2) >> 4 );
    RX = (TInt32)( (aParams->currx + RPF2) >> 4 );
    LY = (TInt32)( (aParams->curry - RPF2) >> 4 );
    RY = (TInt32)( (aParams->curry + RPF2) >> 4 );

    LX = ( LX < 0 ) ? 0 : LX;
    RX = ( RX > aParams->nW - 1 ) ? aParams->nW - 1 : RX;
    LY = ( LY < 0 ) ? 0 : LY;
    RY = ( RY > aParams->nH - 1 ) ? aParams->nH - 1 : RY;

    if ( RX < LX )
    {
        return;
    }

    TRect rtDraw( LX, LY, RX, RY );
    if ( aParams->rtAffected.IsEmpty() )
    {
        aParams->rtAffected = rtDraw;
    }
    else
    {
        aParams->rtAffected.BoundingRect( rtDraw );
    }

    RPF2 *= RPF2;
    RMF2 *= RMF2;

    RPMF2 = d * 2;

    // Optimization run: find squares of X first
    for ( x = LX; x <= RX; x++ )
    {
        y = (x << 4) - aParams->currx;
        aParams->SqX[x] = y * y;
    }

    // Loop through Y values
    for ( y = LY; y <= RY; y++ )
    {
        aParams->bits->SetPos( TPoint( LX, y ) );
        aParams->mask->SetPos( TPoint( LX, y ) );

        SqY = (y << 4) - aParams->curry;
        SqY *= SqY;
        // Loop through X values
        for ( x = LX; x <= RX; x++ )
        {
            // determine squared distance from center for this pixel
            SqDist = SqY + aParams->SqX[x];
            // inside inner circle? Most often..
            if ( SqDist < RMF2 )
            {
                if ( !aParams->mask->GetPixel() )
                {
                    aParams->bits->SetPixel( color );
                }
                // inside the inner circle.. give the scanline the new color
                TUint8 a = (TUint8)( aParams->mask->GetPixel() & 0xFF );
                a = (TUint8)( 128 + ( a >> 1 ) );
                aParams->mask->SetPixel( a ); //mask bitmap must be EGray256
            }
            else
            {
                // inside outer circle?
                if ( SqDist < RPF2 )
                {
                    // We are inbetween the inner and outer bound, now mix the color
                    nFact = (18 - (SqDist - RMF2) / RPMF2) / 3;
                    if ( nFact > 0 )
                    {
                        if ( !aParams->mask->GetPixel() )
                        {
                            aParams->bits->SetPixel( color );
                        }
                        TUint8 a = (TUint8)(aParams->mask->GetPixel() & 0xFF);
                        a = (TUint8)( 16 * nFact + ((a * (16 - nFact)) >> 4) );
                        aParams->mask->SetPixel( a ); //mask bitmap must be EGray256
                    }
                }
            }

            aParams->bits->IncXPos();
            aParams->mask->IncXPos();
        }