开发者

Black border around characters when draw Image to a transparent Bitmap

开发者 https://www.devze.com 2022-12-09 15:17 出处:网络
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.

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,
  开发者_StackOverflow社区  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!


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++ ;)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消