473,396 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

.NET GIF Image Quality

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
4 1745
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sean | last post by:
i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of...
5
by: Popoxinhxan | last post by:
HI guy I am working on the web application that required to display the chart image on the page. The process is clicking the button and browser will popup another windows that displayed...
6
by: Chris D | last post by:
Hi, I have an application where a user uploads an image and I create two thumbnails. One a small image and the second is a larger image but still smaller then the original. I store these in SQL...
6
by: neverstill | last post by:
hi- So I wrote this nice little page that will allow the managers to add images to the products table. Without too many details to confuse everything, basically what I'm doing is: getting an...
7
by: somequestion | last post by:
System.Drawing.Image newImage = Bitmap(....) newImage.Save(destinationPath, ImageFormat.Jpeg); this image resolution is very low i'd like to make high quality image so i change...
1
by: Daniel Mark | last post by:
hello all: I am using Image module from PIL to save created image as JPG format. Is there any option I could set for function Image.save so that the stored image will have the highest quality....
9
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to...
11
by: shapper | last post by:
Hello, I am displaying an image on a few pages. The image size is 50 px height and 50 px width. In some pages I need the image to be 30x30 px in others 40x40 px and in others 50x50px. Can I...
8
by: JJ | last post by:
Whilst I am resizing images I am losing quality. This is only happening in small amounts, but if you repeatedly put the same image through the following code, the image quality slowly degrades. Can...
1
by: Sinan Alkan | last post by:
Hi All, I have a method to resize any image file to the specific dimensions and save this new image to a path. I found it on a web page(By Joel Neubeck) and i changed it for my project. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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,...

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.