.NET GIF Image Quality

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

}
 
J

Juan T. Llibre

re:
1) How to I get around this issue? This code needs high trust permission, but my hosting only
allows "medium"

The only *real* answer to this is that you must control your server,
so you can configure high trust permissions, if you're going to offer
the type of service which requires such permissions but your hosting
environment balks at letting you set the needed permissions.

You need a dedicated or, at least, a co-located server.
 
S

Steven Cheng[MSFT]

Thanks for Juan's input.

Hi Liming,

I agree with Juan that such operations do require high permission in .NET
CAS. And if possible, I suggest you ask for the webhoster to see whether
they can provide a workaround to level up the permission setting.
BTW, one approach to run unsafe code in restricted permission environment
is to encapsulate the unsafe code in a certain class library(assembly),
strong named it and put it in GAC, assembly in GAC will have full trust
permission. However, this also need to support on the web host side.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

thought about co-location, but too $$$.. is there another way that I can
improve .GIF quality and not use unsafe code? the GIF is REALLY bad.
 
S

Steven Cheng[MSFT]

Hi Liming,

Thanks for your response. I'm afraid so far we're limited to those
solutions which require high CAS permission since such image quality
processing usually deal with raw bit data directly. Any other better web
hoster which provide more customization allowance?

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top