Click here to Skip to main content
15,895,792 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# and Managed DirectX Invalid Rectangle Pin
James T. Johnson2-Jun-03 10:59
James T. Johnson2-Jun-03 10:59 
GeneralRe: C# and Managed DirectX Invalid Rectangle Pin
EvilDingo3-Jun-03 1:36
EvilDingo3-Jun-03 1:36 
GeneralRe: C# and Managed DirectX Invalid Rectangle Pin
Anonymous3-Jun-03 1:58
Anonymous3-Jun-03 1:58 
GeneralRe: C# and Managed DirectX Invalid Rectangle Pin
James T. Johnson3-Jun-03 2:00
James T. Johnson3-Jun-03 2:00 
GeneralRe: C# and Managed DirectX Invalid Rectangle Pin
EvilDingo3-Jun-03 4:27
EvilDingo3-Jun-03 4:27 
GeneralSelected row from a ListView Pin
quicksilver02022-Jun-03 1:03
quicksilver02022-Jun-03 1:03 
Generalexisting code from c++ Pin
stonee741-Jun-03 22:26
stonee741-Jun-03 22:26 
GeneralGif compression using Save method on bitmap class Pin
christiantoivola1-Jun-03 22:08
christiantoivola1-Jun-03 22:08 
Hi,

I have been trying to save images as gifs, but I am dissatisfied with the results. The colors are reduced drastically, even if I have specified a highquality pixelformat. I tried changing all kinds of variables such as CompositingMode, SmoothingMode, InterpolationMode, COmpositingQuality etc. Nothing works. However, when I save the image as a jpg, then the color reduction is not as drastic.

I am starting to suspect that the color reduction occurs when the bitmap is saved, in which case the problem most likely has to do with the Gif compression and any settings you can pass to the codec.

Does anyone know how you specify the gif compression when using the Save Method? Where can I read about the compression alternatives? I have already managed to see all my codecs and their properties, but it is of no use to me.

<br />
<%@ Import Namespace="System" %><br />
<%@ Import Namespace="System.IO" %><br />
<%@ Import Namespace="System.Collections" %><br />
<%@ Import Namespace="System.ComponentModel" %><br />
<%@ Import Namespace="System.Data" %><br />
<%@ Import Namespace="System.Drawing" %><br />
<%@ Import Namespace="System.Drawing.Drawing2D" %><br />
<%@ Import Namespace="System.Drawing.Imaging" %><br />
<%@ Import Namespace="System.Drawing.Text" %><br />
<script language="C#" runat="server"><br />
<br />
static PrivateFontCollection pf; <br />
<br />
// Initiates the fonts in the directory specified<br />
static void InitPF(string path) <br />
{<br />
	pf = new PrivateFontCollection();<br />
	string[] ttfs = Directory.GetFiles(path, "*.ttf");<br />
<br />
	for (int i = 0; i<ttfs.Length; i++){<br />
		pf.AddFontFile(ttfs[i]);<br />
	}<br />
}<br />
<br />
public static FontFamily[] GetFonts(string path)<br />
{<br />
	if (pf == null) InitPF(path);<br />
		return (FontFamily[]) pf.Families.Clone();<br />
}<br />
<br />
void Page_Load(Object sender, EventArgs e)<br />
{<br />
<br />
	FontFamily[] pf = GetFonts(Server.MapPath(""));<br />
	<br />
<br />
<br />
	// Create a Bitmap instance that's 468x60, and a Graphics instance<br />
	const int width = 300, height = 41;<br />
	Bitmap objBitmap = new Bitmap(width, height, PixelFormat.Format64bppArgb);<br />
	//objBitmap.PixelFormat = ;<br />
	Graphics objGraphics = Graphics.FromImage(objBitmap);<br />
<br />
	// Inerpolation mode; affects the way an image scales.<br />
	//objGraphics.InterpolationMode = InterpolationMode.Bicubic;<br />
<br />
	// Controls whether smoothing is applied to lines, curves and edges.<br />
	//objGraphics.SmoothingMode = SmoothingMode.HighQuality;<br />
<br />
	//objGraphics.CompositingMode = CompositingMode.SourceOver;<br />
<br />
	// Sets quality of the composite during rendering.<br />
	//objGraphics.CompositingQuality = CompositingQuality.HighQuality;<br />
<br />
	// Create a white background for the border<br />
	objGraphics.FillRectangle(new SolidBrush( Color.White ), 0, 0, width, height);<br />
<br />
	Bitmap objTile = new Bitmap(Server.MapPath(Request.ApplicationPath) + "\\uploads\\title_tile.gif");<br />
	objGraphics.DrawImage(objTile, 0, 0, objTile.Width, objTile.Height);<br />
<br />
<br />
	// Create the advertising pitch<br />
	String adPitch = "gif compression";<br />
<br />
	//initiate new variables<br />
	int count = 0;<br />
	//font familyName;<br />
	string familyNameAndStyle;<br />
		<br />
	// How many objects in the fontFamilies array?<br />
	count = pf.Length;<br />
<br />
	// Specify the font and alignment<br />
<br />
	// center align the advertising pitch<br />
	StringFormat stringFormat = new StringFormat();<br />
	//stringFormat.Alignment = StringAlignment.Center;<br />
	//stringFormat.LineAlignment = StringAlignment.Center;<br />
<br />
	   if(pf[count - 1].IsStyleAvailable(FontStyle.Regular))<br />
	   {<br />
			myLabel.Text = objBitmap.PixelFormat + "<br>";<br />
			myLabel.Text += pf.ToString() + "<br>";<br />
			myLabel.Text += pf[count - 1].Name + "<br>";<br />
			myLabel.Text += pf.Length + "<br>";<br />
<br />
		  //familyName = pf[count - 1].Name;<br />
		 //(font) nFont = pf[count - 1].Name.ToLower();<br />
<br />
	      Font regFont = new Font(<br />
	         pf[count - 1],<br />
	         16);<br />
	<br />
<br />
	    objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;<br />
		objGraphics.DrawString(adPitch, regFont, new SolidBrush(Color.FromArgb(255, 0, 51, 102)), <br />
					 new Rectangle(24, 0, width, height), stringFormat);<br />
		regFont.Dispose();<br />
	   }<br />
		else{<br />
					myLabel.Text = "Not found"<br />
		}<br />
<br />
<br />
    objBitmap.Save(Server.MapPath(Request.ApplicationPath) + "\\uploads\\banner.gif", ImageFormat.GIf);<br />
    objGraphics.Dispose();<br />
    objBitmap.Dispose();<br />
}<br />
<br />
</script><br />
<br />
<br />
<asp:label id="myLabel" runat="server" /><br />


Regards,

Christian Toivola
GeneralRe: Gif compression using Save method on bitmap class Pin
Richard Deeming1-Jun-03 23:33
mveRichard Deeming1-Jun-03 23:33 
Generalshow tooltip Pin
grv5751-Jun-03 20:16
grv5751-Jun-03 20:16 
GeneralRe: show tooltip Pin
Singh, Manish2-Jun-03 20:44
Singh, Manish2-Jun-03 20:44 
GeneralSystem.NullReferenceException in RichTextBox while dynamically adding text Pin
CNU1-Jun-03 19:58
CNU1-Jun-03 19:58 
GeneralCreate a remort object in C# Pin
Gaurika Wijeratne1-Jun-03 17:54
Gaurika Wijeratne1-Jun-03 17:54 
GeneralRe: Create a remort object in C# Pin
Kannan Kalyanaraman1-Jun-03 22:17
Kannan Kalyanaraman1-Jun-03 22:17 
GeneralRe: Create a remort object in C# Pin
Gaurika Wijeratne1-Jun-03 22:39
Gaurika Wijeratne1-Jun-03 22:39 
Generalurgent help needed, event handler Pin
mtrx1-Jun-03 17:35
mtrx1-Jun-03 17:35 
GeneralRe: urgent help needed, event handler Pin
Ray Cassick1-Jun-03 17:55
Ray Cassick1-Jun-03 17:55 
GeneralRe: urgent help needed, event handler Pin
mtrx2-Jun-03 3:41
mtrx2-Jun-03 3:41 
GeneralRe: urgent help needed, event handler Pin
shaunAustin3-Jun-03 1:25
shaunAustin3-Jun-03 1:25 
GeneralCustom Control Events Pin
Tym!1-Jun-03 12:05
Tym!1-Jun-03 12:05 
GeneralSome Progress, Sound good? Pin
Tym!1-Jun-03 13:23
Tym!1-Jun-03 13:23 
QuestionGDI+, How to stop antialias? Pin
FruitBatInShades31-May-03 23:51
FruitBatInShades31-May-03 23:51 
AnswerRe: GDI+, How to stop antialias? Pin
leppie1-Jun-03 0:07
leppie1-Jun-03 0:07 
GeneralRe: GDI+, How to stop antialias? Pin
FruitBatInShades1-Jun-03 0:44
FruitBatInShades1-Jun-03 0:44 
QuestionHow to extend System.Int32? Pin
ralfoide31-May-03 15:58
ralfoide31-May-03 15:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.