Friday, June 15, 2007

Optimizing rendered image

I realized the png I render the text to will end up with color matching issues (I've found this in general with some pngs).

I found a cool way to have it render a gif with an optimized palette using some code from Morgan Skinner who wrote an article “Optimizing Color Quantization for ASP.NET Images”.

Add this dll to your references:

ImageManipulation.dll

now with "using ImageManipulation;"

you can change the line textImage.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); in the code I wrote earlier to:

OctreeQuantizer quantizer = new OctreeQuantizer(255, 8);
Bitmap quantized = quantizer.Quantize(textImage);
Response.ContentType = "image/gif";
quantized.Save(memStream, ImageFormat.Gif);


Labels: , , , , , , ,

1 Comments:

Blogger Ion said...

works 100%!

Thanks!

4:45 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home