By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

.NET GIF Image Quality

P: n/a
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/de...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...;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.HighQua lityBicubic;

oGraphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality ;

oGraphics.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuali ty;

oGraphics.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.HighQu ality;

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

}

Apr 4 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Liming" <ro*****@nospam.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... 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/de...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"

Apr 4 '06 #2

P: n/a
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.)

Apr 4 '06 #3

P: n/a
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.

"Steven Cheng[MSFT]" wrote:
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.)

Apr 4 '06 #4

P: n/a
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.)

Apr 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.