473,659 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


Mar 1 '06 #1
2 3457
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).

EncoderParamete r testParam = new
EncoderParamete r(System.Drawin g.Imaging.Encod er.Quality, (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******** ******@TK2MSFTN GP14.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 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
-------------------------------------------------------

Mar 3 '06 #3

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

Similar topics

2
2026
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 either SP1 or SP2? The system requirements don't list Windows XP. From reading the Security Bulletin I was thought it applied to Windows XP, though it doesn't directly say so. -- Dale
0
1365
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 installer was "Gathering required information". The event viewer shows: Product: Visual Studio .NET Professional 2003 - English - Update '{BBDEF0B4-0C24-4812-80C6-9207B26285E8}' could not be installed. Error code 1603. Additional information is...
7
3291
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 access denied using resizeTo. I am having the same issue but the explanations in this article don't seem to apply here. I am not trying to resize a window with content from a different server. This issue lies here. What I do is make a popup...
2
2460
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 workstation it is normally run from has been upgraded to WinXP from WinNT 5.0. The issue is that the graphs will either display the data within the recordsource (a query), OR it will display the "temp" data in the chart's datasheet (from initial...
0
1379
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 GdipWindingModeOutline(PathData path,Matrix m ,float flatness);
1
2941
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 not using any gdi functionality. Could somebody please explain this to me ?? I thought the linker would se that no gdi calls were made and just skip this part....
2
2813
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 intermittantly get the following exception - EXCEPTION MESSAGE: The viewstate is invalid for this page and might be corrupted. STACK TRACE:
7
6628
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, when i statically link the dll and run the application on target (W2K) machine it throws an exception saying GDIPlus.dll file not found. Please help.
13
3493
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 allowing the user to make a selection from the popup window. I have enabled AJAX extensions and have a working sample outside of a gridview. However, when I click in the textbox of a gridview row, all I see is a really small square instead of the...
4
13961
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 and most performent way of resizing a jpg file from MegaPixel format to 640 * 480 size. Gdiplus currently offers the fastest way for me with a result of 3ms / resize. I am however recieving random Access Violations exceptions and the small tool...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.