473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GDIplus issue

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,enco derParams);

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


Mar 1 '06 #1
2 3450
What you are looking for is the Quaility parameter, not the Compression
parameter. For some reason the parameter needs to be passed as
(therefore cast to) a long (I'm guessing it's an overload thing).

EncoderParameter testParam = new
EncoderParameter(System.Drawing.Imaging.Encoder.Qu ality, (long)100);
//100 is probably more than you need.

Mar 1 '06 #2
Thanks, that worked like a treat.

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

"Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
news:OP**************@TK2MSFTNGP14.phx.gbl...
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,enco derParams);

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

Mar 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dale | last post by:
For the MS04-028 Security Bulletin (GDI+) it refers Visual Studio 2003 users to KB830348, which is the Visual Studio .NET 2003 GDIPLUS.DLL Security Update. Does this apply to Windows XP with...
0
by: SirPurple | last post by:
With the various GDIPLUS.DLL files floating about my system, I wanted to update them all using the relevant security updates available. The update for VS.NET 2003 failed miserably while the...
7
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with...
2
by: Anthony Cuttitta Jr. | last post by:
We have an application that outputs several different graphs from data downloaded from our AS400. The application has worked without (this) issue for several months now, but just recently, the...
0
by: SG | last post by:
Hi, does anybody know how to access forgotten gdiplus functions in C# I have tried it with the GDIplus Flat API. Unfortunately it doesent work. public static extern int ...
1
by: Espen Løke | last post by:
I am using VS.NET 2003 to created a mixed mode exe. I am not using any gdi functions and it compiles fine. If I just include gdiplus.h the linker forces me to link in gdiplus.lib although I am...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
7
by: =?Utf-8?B?UmFtZW5kcmEgS290aGFya2Fy?= | last post by:
Hello, I want to know how to statically link GDIPlus.dll with VC++ application that should be able to run on W2k machine without the existence of GDIPlus.dll on the target machine. Currently,...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
4
Airslash
by: Airslash | last post by:
Hello, been a while since I visited bytes.com, but I have an issue with GDIplus... I'm currently developing on/for a Windows Server 2003 system and I'm running a Benchmark to find the fastest...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.