Web Site Images

B

Brett Ossman

We previously used the System.Drawing namespace for image management in our
web app. System.Drawing is not reliable for web apps, and even Microsoft
says that in their page about System.Drawing.

Should I be looking at Silverlight now?

One specific issue I have is to determine an image's dimensions at run-time.
Note, not the asp:image control's dimensions, the dimensions of the image
itself.

Any ideas?

Thanks
Brett Ossman
 
S

sqlman

We previously used the System.Drawing namespace for image management in our
web app. System.Drawing is not reliable for web apps, and even Microsoft
says that in their page about System.Drawing.

Should I be looking at Silverlight now?

One specific issue I have is to determine an image's dimensions at run-time.
Note, not the asp:image control's dimensions, the dimensions of the image
itself.

Any ideas?

Thanks
Brett Ossman

Brett,

For something like determining image sizes, you may still rely on
System.Drawing. I.e., try before you jump to any conclusion. Most
likely you'd be fine. System.Drawing may be considered bad because it
uses GDI+ as its backend for image displaying and manipulation, which
may not be the best thing when running within server-side code anyway.

As far as you're talking about server-side functionality, Silverlight
is not much of a help here: it is a client-side technology.
 
G

Guest

We previously used the System.Drawing namespace for image management in our
web app.  System.Drawing is not reliable for web apps, and even Microsoft
says that in their page about System.Drawing.

Should I be looking at Silverlight now?

One specific issue I have is to determine an image's dimensions at run-time.
Note, not the asp:image control's dimensions, the dimensions of the image
itself.

Any ideas?

Thanks
Brett Ossman

I don't get what's the problem there with dimensions and
System.Drawing

just use

System.Drawing.Bitmap b = new Bitmap(filename);
Response.Write (b.Height + b.Width);
 
K

Kornél Pál

There are two weaknesses:

GDI+ is not thread safe at all. That means that you shouldn't/sometimes
can't even read the same image object from two different threads. I
recommend to create new Bitmap instances on each thread and store it
using WeakReferences in ThreadStatic fields. If you just need the
dimesions the you should cache the dimensions only.

The other issue is that if you open an image from a stream then that
stream will be used every time you read the image. If you want to use
the image frequently you should convert it to a memory bitmap: bitmap =
new Bitmap(oldBitmap);

Kornél
 
B

bruce barker

you should not use thread static fields with asp.net, as the same thread
may not be used throughout the request processing.

-- bruce (sqlwork.com)
 
B

Brett Ossman

Thanks for the replies.

I realize I shouldn't be using System.Drawing. I was wondering what
approach I should take for image management and manipulation, such as the
issue I presented. Is Silverlight the way to go, or are there other ASP .Net
based options?

Thanks again
Brett Ossman
 
K

Kornél Pál

ASP.NET is simply a multi-threaded application.

So you can use thread static variables if you only need to read image
multiple times. Of course you will have to create the image if it
doesn't exists but you can cache the results and don't have to use locks.

Other imaging libraries most likely support reading images from multiple
treads without locks.

If wou want to write to the image from multiple threads you will need to
use lock regardless of the imaging library you use.

Note that if you only want to access the image from a single thread the
you don't have to do anything special just create and use the image.

Kornél
 
B

bruce barker

as asp.net makes callbacks (calls events) during request processing, it
can use different threads from the pool (thread agility). the same
thread is not necessarily used for the complete request.

this means its safe to use thread statics inside a single callback
function (to pass data to called routines), but not between events (say
a on page load handler and a on click handler).

if you use thread statics, then you should use aspcompat which will
force your requests to a single thread (at a performance cost).

-- bruce (sqlwork.com)
 
A

Andrew Morton

Brett said:
We previously used the System.Drawing namespace for image management
in our web app. System.Drawing is not reliable for web apps, and
even Microsoft says that in their page about System.Drawing.

Cite? If you're referring to the sentence "Classes within the System.Drawing
namespace are not supported for use within a Windows or ASP.NET service,"
then notice it says "service", not "application".

http://msdn.microsoft.com/en-us/library/system.drawing.aspx
Should I be looking at Silverlight now?

No. That is something completely different. Silverlight runs in a browser.
Any ideas?

You could read the first part of the file with ordinary file operations and
parse it to get the dimensions.

Andrew
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top