A
Alvin Bruney - ASP.NET MVP
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 CreateDynamicImage()
{
WebClient webclient = new WebClient();
bmpBook=(Bitmap)
System.Drawing.Image.FromStream(webclient.OpenRead(urlBaseImage));
EncoderParameter testParam= new
EncoderParameter(Encoder.Compression,100);
EncoderParameters encoderParams= new EncoderParameters(1);
encoderParams.Param[0]= testParam;
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
bmpFinal= new Bitmap(bmpBook.Width, bmpBook.Height);
System.Drawing.Graphics g =
System.Drawing.Graphics.FromImage(bmpFinal);
g.DrawImage(bmpBook, 0, 0, bmpBook.Width, bmpBook.Height);
//drawing some other texts and shapes
...
Response.Clear();
Response.ContentType="image/jpeg";
bmpFinal.Save(Response.OutputStream,jpegCodec,encoderParams);
bmpBook.Dispose();
bmpFinal.Dispose();
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
-------------------------------------------------------
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 CreateDynamicImage()
{
WebClient webclient = new WebClient();
bmpBook=(Bitmap)
System.Drawing.Image.FromStream(webclient.OpenRead(urlBaseImage));
EncoderParameter testParam= new
EncoderParameter(Encoder.Compression,100);
EncoderParameters encoderParams= new EncoderParameters(1);
encoderParams.Param[0]= testParam;
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
bmpFinal= new Bitmap(bmpBook.Width, bmpBook.Height);
System.Drawing.Graphics g =
System.Drawing.Graphics.FromImage(bmpFinal);
g.DrawImage(bmpBook, 0, 0, bmpBook.Width, bmpBook.Height);
//drawing some other texts and shapes
...
Response.Clear();
Response.ContentType="image/jpeg";
bmpFinal.Save(Response.OutputStream,jpegCodec,encoderParams);
bmpBook.Dispose();
bmpFinal.Dispose();
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
-------------------------------------------------------