I'm using C# and GDI+ to create dynamic images and show them on the
web. I'm loading the main image which is a jpeg, then I'm drawing some
text and shapes on that base image using Graphics class of GDI+, at the
end I'm sending the new image to output.
My problem is when I use GDI+, I loose some quality of the base image.
Although I'm using jpeg Compression = 100, I still have some artifacts
on the output image. Some colors on the base image are also lost.
I load the base jpeg image as a bitmap, It doesn't have any palettes
after I load it. and I can't set any palettes for it, to do some
possible changes on pallete and improve the quality.
How can I improve the quality WITHOUT using UNSAFE code in C#?
Any help appreciated.
Thanks,
here is my code:
public void CreateDynamicIm age()
{
WebClient webclient = new WebClient();
bmpBook=(Bitmap )
System.Drawing. Image.FromStrea m(webclient.Ope nRead(urlBaseIm age));
EncoderParamete r testParam= new
EncoderParamete r(Encoder.Compr ession,100);
EncoderParamete rs encoderParams= new EncoderParamete rs(1);
encoderParams.P aram[0]= testParam;
ImageCodecInfo jpegCodec = GetEncoderInfo( "image/jpeg");
bmpFinal= new Bitmap(bmpBook. Width, bmpBook.Height) ;
System.Drawing. Graphics g =
System.Drawing. Graphics.FromIm age(bmpFinal);
g.DrawImage(bmp Book, 0, 0, bmpBook.Width, bmpBook.Height) ;
//drawing some other texts and shapes
...
Response.Clear( );
Response.Conten tType="image/jpeg";
bmpFinal.Save(R esponse.OutputS tream,jpegCodec ,encoderParams) ;
bmpBook.Dispose ();
bmpFinal.Dispos e();
g.Dispose();
}
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------