User314661392 posted
Hey, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Since it took me so long to find the solution for a transparent background, <o:p></o:p>
(For some reason I couldn’t find it in this respectable forum)<o:p></o:p>
I figured that my time won’t to be more productive if I share with you my findings <o:p></o:p>
So here there are:<o:p> </o:p>
The problem: A
Dithery, grainy image is produced from the myGifImage.Save, and the transparent background
is actually black<o:p></o:p>
The Solution:
There is a free code that implements a
OctreeQuantizer function. This solves the above problem.<o:p></o:p>
(You’ll need to add the OctreeQuantizer.cs and Quantizer.cs to your App_Code folder in your project )<o:p></o:p>
And than call it :<o:p></o:p>
OctreeQuantizer quantizer =
new OctreeQuantizer ( 255 , 8 ) ;<o:p></o:p>
<o:p> </o:p>
using ( Bitmap quantized = quantizer.Quantize(objBitmap) )<o:p></o:p>
{<o:p></o:p>
quantized.Save(FileName, ImageFormat.Gif);<o:p></o:p>
}<o:p></o:p>
You can find this code here:
http://codebetter.com/blogs/brendan.tompkins/archive/2004/01/26/6103.aspx<o:p></o:p>
<o:p> </o:p>
Another problem I had was:
using Graphics.DrawString on transparent background you get the ugly font while if the background is not transparent it looks fine.<o:p></o:p>
The solution:
Add a rendering hint just prior to the DrawString statement <o:p></o:p>
g.TextRenderingHint =
TextRenderingHint.SingleBitPerPixelGridFit; //
<— This line solved it !
g.DrawString(text, font, Brushes.Black,
new Point(x, 0));<o:p></o:p>
This is where I find this wonderful solution:
http://weblogs.asp.net/israelio/archive/2006/05/06/445428.aspx<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>