Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Transparent antialias text problem

Transparent antialias text problem

Scheduled Pinned Locked Moved .NET (Core and Framework)
graphicscsharphelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peter Trevor
    wrote on last edited by
    #1

    I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)

    H S P 3 Replies Last reply
    0
    • P Peter Trevor

      I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      I found this[^], which seems to have some work arounds, from a quick google on c# antialias problems The link above is from fairly near the top of a loooooong list.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      1 Reply Last reply
      0
      • P Peter Trevor

        I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)

        S Offline
        S Offline
        supercat9
        wrote on last edited by
        #3

        I don't think it's possible to generate a semi-transparent bitmap with a single alpha value per pixel which will properly render ClearType text against arbitrarily-colored backgrounds (when drawing yellow text on a black background, a particular pixel may have to be red, but when drawing on a white background it may have to be yellow). If one refrains from ClearType-style use of colors for sub-pixel addressing, one could generate a bitmap that would depict a nicely anti-aliased font when overlaid on any background, by setting the color of any area of the bitmap which touched the letters to the font color, and varying the alpha to properly soften the edges. I don't think that's what Microsoft does, though. Still, you might want to experiment some with the property (I forget what it's called) that switches between drawing using an alpha value, or copying an alpha value to drawn pixels). It would be nice if there were a way of restricting drawing operations to either act only on the alpha channel, or leave the alpha channel alone while acting on color. I'm unaware of how to do those things, though.

        1 Reply Last reply
        0
        • P Peter Trevor

          I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)

          P Offline
          P Offline
          Peter Trevor
          wrote on last edited by
          #4

          Okay. After playing around with a number of options without luck I decided to try a completely different approach. What I did was to create a second (temporary) bitmap with the same dimensions as the transparent target but with a white background. I then wrote on it in black. Finally I merged this into the transparent bitmap by examing each pixel in my second bitmap and setting the corresponding pixel in the target with RGB set to the target colour and the 'A' byte set to 255 - ((old R + old G + old B) / 3). Surprisingly, this worked and gives me true antialias to transparent. :-D If anyone's interested I've posted the code here [^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups