Question

I have to draw a String on a transparent bitmap at first, then draw A to destination canvas. However on certain case, there is black border around the characters.

Bitmap* tempImg = new Bitmap(1000, 1000, PixelFormat32bppARGB);
Graphics tempGr(tempImg);
tempGr.Clear(Color(0, 255,255,255));
Gdiplus::SolidBrush* brush = new SolidBrush(Color(255, 255, 0, 0 ));
Gdiplus::FontFamily  fontFamily(L"Times New Roman");
Gdiplus::Font*  font = new Gdiplus::Font(&fontFamily, 19, FontStyleRegular, UnitPixel);
RectF rec(400, 400, 1000, 10000);
tempGr.DrawString(
    L"Merry Chrismas", 
    -1,
    font,
    rec,
    NULL,
    brush
    );

Graphics desGr(hdc);
desGr.Clear(Color::Gray);
desGr.DrawImage(tempImg , 0,0, 1000, 1000);

The character draw on desGr have black board for some fontsize.

How can I avoid this problem? Many thanks!

Was it helpful?

Solution

I think the problem here is that you are drawing the text onto a transparent background.

You could try adding this line after the call to tempGr.Clear...

tempGr.TextRenderingHint = TextRenderingHint.AntiAlias;

ps - sorry not sure the exact syntax in C++ ;)

OTHER TIPS

I just solved this problem in XNA:

Clear background to the same as the foreground color. The only difference is that the background should have Alpha=0, and the foreground with Alpha >> 0

The black border comes from blending of your background and foreground of different colors. Try to clear the background to some contrasting color to fully appreciate the phenomenon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top