Can you make an alpha transparent PNG with C#?

后端 未结 9 1745
陌清茗
陌清茗 2020-12-02 14:31

I have a multi-browser page that shows vertical text.

As an ugly hack to get text to render vertically in all browsers I\'ve created a custom page handler that retur

9条回答
  •  庸人自扰
    2020-12-02 14:58

    Sorry, I didn't read your question carefully enough.

    I know that I have successfully drawn rotated text on a colored background without seeing either of the aliasing effects in your examples. When I went back to look at my code, I realized that I was drawing the rotated text using a logical font, which is nicely wrapped in the Microsoft.WindowsCE.Forms namespace. This technique sets the drawing angle as a property of the logical font (so you don't call TranslateTransform or RotateTransform).

    Outside of the Windows CE world, you have to PInvoke to create a logical font (I've never done this and I couldn't find a good example quickly). I don't know how well this would perform, but I know for sure that it will draw rotated text without the weird aliasing effects you're seeing. I think for sure this is a bug in GDI+ (or just something they didn't think anyone would ever really use).

    An alternative approach that might even perform better than the logical font is to draw the text normally on a colored rectangle background (just large enough to hold the text), then rotate-and-copy the rectangle onto your main image. Graphics.DrawImage doesn't appear to be able to do rotation, but this effect is easy to implement using LockBits.

提交回复
热议问题