Home > Back-end >  Vc drawing clear text does not display problem, realize the text fade
Vc drawing clear text does not display problem, realize the text fade

Time:09-24

Learning drawing text, the realization of the text fade effect, want to use alphablend function to realize the fade, but encountered a problem, the following two types of call, one of the method is feasible, a method is not feasible,
A:
HBitmapDC=CreateCompatibleDC ( HDC ).
HBitmap=CreateCompatibleBitmap ( HDC , w, h);
SelectObject (hBitmapDC hBitmap);
SetTextColor (hBitmapDC, RGB (0, 255));
SetBkColor (hBitmapDC, RGB (0, 0 xaa, 0));

TextOut (hBitmapDC, 20, 50, szText strlenT (szText));
Bf. BlendOp=AC_SRC_OVER;
Bf. BlendFlags=0;
Bf. SourceConstantAlpha=120;
Bf. AlphaFormat=AC_SRC_ALPHA;
AlphaBlend function (HDC, 0100, w, h, hBitmapDC, 0, 0, w, h, bf);

DeleteObject (hBitmap);
DeleteDC (hBitmapDC);
Effect as shown in figure:


The second way:
HBitmapDC=CreateCompatibleDC (HDC);
HBitmap=CreateCompatibleBitmap ( hBitmapDC , w, h);//not do

//hBitmapDC=CreateCompatibleDC (NULL);
//hBitmap=CreateCompatibleBitmap ( hBitmapDC , w, h);//not do

SelectObject (hBitmapDC hBitmap);
SetTextColor (hBitmapDC, RGB (0, 255));
SetBkMode (hBitmapDC, OPAQUE);
SetBkColor (hBitmapDC, RGB (0, 0 xaa, 0));

TextOut (hBitmapDC, 20, 50, szText strlenT (szText));
Bf. BlendOp=AC_SRC_OVER;
Bf. BlendFlags=0;
Bf. SourceConstantAlpha=120;
Bf. AlphaFormat=AC_SRC_ALPHA;
AlphaBlend function (HDC, 0100, w, h, hBitmapDC, 0, 0, w, h, bf);

DeleteObject (hBitmap);
DeleteDC (hBitmapDC);
Effect as shown in figure:


This is why, CreateCompatibleBitmap compatibleDC cannot be used?

Please directly


CodePudding user response:

Finally found a feasible way to

BITMAPINFOHEADER bih.
Memset (& amp; Bih, 0, sizeof (BITMAPINFOHEADER));
Bih. BiSize=sizeof (BITMAPINFOHEADER);
Bih. BiHeight=h;
Bih. BiWidth=w;
Bih. BiPlanes=1;
Bih. BiBitCount=32;
Bih. BiCompression=BI_RGB;
BYTE * m_pBits=NULL;

HBitmapDC=CreateCompatibleDC (NULL);//feasible
//hBitmapDC=CreateCompatibleDC (HDC);//feasible
HBitmap=: : CreateDIBSection (hBitmapDC, (BITMAPINFO *) & amp; Bih,
DIB_RGB_COLORS, (void * *) (& amp; M_pBits), NULL, 0);

//hBitmapDC=CreateCompatibleDC (HDC);
//hBitmap=CreateCompatibleBitmap (hBitmapDC, w, h);//not do

//hBitmapDC=CreateCompatibleDC (NULL);
//hBitmap=CreateCompatibleBitmap (hBitmapDC, w, h);//not do

SelectObject (hBitmapDC hBitmap);
SetTextColor (hBitmapDC, RGB (0, 255));
SetBkMode (hBitmapDC, OPAQUE);
SetBkColor (hBitmapDC, RGB (0, 0 xaa, 0));

TextOut (hBitmapDC, 20, 50, szText strlenT (szText));

Bf. BlendOp=AC_SRC_OVER;
Bf. BlendFlags=0;
Bf. SourceConstantAlpha=20;
Bf. AlphaFormat=AC_SRC_ALPHA;
AlphaBlend function (HDC, 0100, w, h, hBitmapDC, 0, 0, w, h, bf);

DeleteObject (hBitmap);
DeleteDC (hBitmapDC);
  • Related