L
Liming
Hi,
I've managed to create a bitmap and output it via the httphandler by setting
Response.ContentType="image/gif"
the resulting GIF quality is REALLY bad. I searched around the web, the only
solution I found was this article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/colorquant.asp
while the code works fine on my localhost. After uploaded to the hosting
enviornment, because the code use unsafe code, i get permission deniend
issue.
so
1) How to I get around this issue? This code needs high trust permission,
but my hosting only allows "medium"
2) How to Create GIF that genereates decent quality other than the above
example? (NOTE: I've seen this example on the web as well
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q319061
but it uses unsafe code as well. No can't do.
3) Is there an .NET 2.0 improve in regards to this area? If so, could you
show me a piece of heaven?
thanks
LIming
In case you are interesting... this is the core part where I gerneated my
image..
Bitmap objImageLeft = new Bitmap(System.Drawing.Image.FromFile(leftFile));
objImageLeft.SetResolution(dpix, dpixy);
Bitmap objImageMid = new Bitmap(System.Drawing.Image.FromFile(midFile));
objImageMid.SetResolution(dpix, dpixy);
TextureBrush objBrush = new TextureBrush(objImageMid);
Bitmap objImageRight = new Bitmap(System.Drawing.Image.FromFile(rightFile));
objImageRight.SetResolution(dpix, dpixy);
int leftwidth = objImageLeft.Width;
int midwidth = objImageMid.Width;
int rightwidth = objImageRight.Width;
int height = objImageMid.Height;
Bitmap imagecontainer = new Bitmap(leftwidth + measured_width+rightwidth,
height);
imagecontainer.SetResolution(dpix, dpixy);
oGraphics = Graphics.FromImage(imagecontainer);
oGraphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
oGraphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
oGraphics.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
oGraphics.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.HighQuality;
oGraphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias;
oGraphics.DrawImage(objImageLeft, 0, 0);
oGraphics.DrawImage(objImageMid, leftwidth, 0);
oGraphics.FillRectangle(objBrush, leftwidth, 0, leftwidth + measured_width,
height);
oGraphics.DrawImage(objImageRight, leftwidth + measured_width, 0);
StringFormat myformat = new StringFormat();
if (String.Compare(ButtonTextAlign, "left")==0)
{
myformat.Alignment = StringAlignment.Near;
}
else if (String.Compare(ButtonTextAlign, "center")==0)
{
myformat.Alignment = StringAlignment.Center;
}
else
{
myformat.Alignment = StringAlignment.Far;
}
myformat.LineAlignment = StringAlignment.Center;
using (Font drawfont = new Font(FontType, FontSize, FontStyle.Bold,
GraphicsUnit.Pixel))
{
Rectangle rect1 = new Rectangle(leftwidth, 0, measured_width, height);
oGraphics.DrawString(text, drawfont, new
SolidBrush(ColorTranslator.FromHtml("#FFFFFF")), rect1, myformat);
/* This is a neat trick to visually identify the boundary */
//oGraphics.DrawRectangle(Pens.Black, rect1);
}
I've managed to create a bitmap and output it via the httphandler by setting
Response.ContentType="image/gif"
the resulting GIF quality is REALLY bad. I searched around the web, the only
solution I found was this article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/colorquant.asp
while the code works fine on my localhost. After uploaded to the hosting
enviornment, because the code use unsafe code, i get permission deniend
issue.
so
1) How to I get around this issue? This code needs high trust permission,
but my hosting only allows "medium"
2) How to Create GIF that genereates decent quality other than the above
example? (NOTE: I've seen this example on the web as well
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q319061
but it uses unsafe code as well. No can't do.
3) Is there an .NET 2.0 improve in regards to this area? If so, could you
show me a piece of heaven?
thanks
LIming
In case you are interesting... this is the core part where I gerneated my
image..
Bitmap objImageLeft = new Bitmap(System.Drawing.Image.FromFile(leftFile));
objImageLeft.SetResolution(dpix, dpixy);
Bitmap objImageMid = new Bitmap(System.Drawing.Image.FromFile(midFile));
objImageMid.SetResolution(dpix, dpixy);
TextureBrush objBrush = new TextureBrush(objImageMid);
Bitmap objImageRight = new Bitmap(System.Drawing.Image.FromFile(rightFile));
objImageRight.SetResolution(dpix, dpixy);
int leftwidth = objImageLeft.Width;
int midwidth = objImageMid.Width;
int rightwidth = objImageRight.Width;
int height = objImageMid.Height;
Bitmap imagecontainer = new Bitmap(leftwidth + measured_width+rightwidth,
height);
imagecontainer.SetResolution(dpix, dpixy);
oGraphics = Graphics.FromImage(imagecontainer);
oGraphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
oGraphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
oGraphics.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
oGraphics.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.HighQuality;
oGraphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias;
oGraphics.DrawImage(objImageLeft, 0, 0);
oGraphics.DrawImage(objImageMid, leftwidth, 0);
oGraphics.FillRectangle(objBrush, leftwidth, 0, leftwidth + measured_width,
height);
oGraphics.DrawImage(objImageRight, leftwidth + measured_width, 0);
StringFormat myformat = new StringFormat();
if (String.Compare(ButtonTextAlign, "left")==0)
{
myformat.Alignment = StringAlignment.Near;
}
else if (String.Compare(ButtonTextAlign, "center")==0)
{
myformat.Alignment = StringAlignment.Center;
}
else
{
myformat.Alignment = StringAlignment.Far;
}
myformat.LineAlignment = StringAlignment.Center;
using (Font drawfont = new Font(FontType, FontSize, FontStyle.Bold,
GraphicsUnit.Pixel))
{
Rectangle rect1 = new Rectangle(leftwidth, 0, measured_width, height);
oGraphics.DrawString(text, drawfont, new
SolidBrush(ColorTranslator.FromHtml("#FFFFFF")), rect1, myformat);
/* This is a neat trick to visually identify the boundary */
//oGraphics.DrawRectangle(Pens.Black, rect1);
}