GDIplus issue

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
-------------------------------------------------------




.



Relevant Pages

  • jpeg palette is lost after loading it as bitmap to work with GDI+ C#
    ... I'm loading the main image which is a jpeg, ... text and shapes on that base image using Graphics class of GDI+, ... My problem is when I use GDI+, I loose some quality of the base image. ...
    (microsoft.public.win32.programmer.gdi)
  • jpeg palette is lost after loading it as bitmap to work with GDI+ C#
    ... I'm loading the main image which is a jpeg, ... text and shapes on that base image using Graphics class of GDI+, ... My problem is when I use GDI+, I loose some quality of the base image. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: loading, Flipping and saving jpgs
    ... You're talking about milliseconds to flip an image, and 10,000 of them could be flipped in very short order. ... You will still need to use a third party library to convert flipped bitmap back into a jpeg, but there are many such libraries freely available that work well with VB6. ... when using such simple methods you really need to ensure that the system is running at full colour depth because loading a jpeg into a PictureBox or into a StdPicture object using the LoadPicture function or by setting a Picture property will degrade the colours when the code is run on a system running at 16 bit colour depth or less. ... You can actually load jpegs into a full colour DIBSection in VB6, even on machines that are running at 16 bits or less, and without using GDI+, but it takes quite a bit of work to do so. ...
    (microsoft.public.vb.general.discussion)
  • Re: Image quality: ImageFormat.Jpeg
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... is there a way to set the output quality of a saved JPEG graphics? ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: jpeg palette is lost after loading it as bitmap to work with GDI+ C#
    ... AFAIK JPEG uses 24 bit colour and does not use palettes. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.framework.drawing)