Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Web Site Images

Reply
Thread Tools

Web Site Images

 
 
Brett Ossman
Guest
Posts: n/a
 
      06-08-2009
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

 
Reply With Quote
 
 
 
 
sqlman
Guest
Posts: n/a
 
      06-08-2009
On Mon, 8 Jun 2009 12:50:01 -0700, Brett Ossman
<(E-Mail Removed)> wrote:

>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.
 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-08-2009
On Jun 8, 9:50*pm, Brett Ossman
<(E-Mail Removed)> wrote:
> 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);
 
Reply With Quote
 
Kornél Pál
Guest
Posts: n/a
 
      06-08-2009
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

Brett Ossman wrote:
> 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
>

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      06-09-2009
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)

Kornél Pál wrote:
> 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
>
> Brett Ossman wrote:
>> 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

 
Reply With Quote
 
Brett Ossman
Guest
Posts: n/a
 
      06-09-2009
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
 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      06-09-2009
>
> Should I be looking at Silverlight now?
>

Of Course as you don't will miss the train and it Visual Studio 2010 it
becomes mature



Cor

 
Reply With Quote
 
Kornél Pál
Guest
Posts: n/a
 
      06-09-2009
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

bruce barker wrote:
> 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)
>
> Kornél Pál wrote:
>> 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
>>
>> Brett Ossman wrote:
>>> 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

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      06-09-2009
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)

Kornél Pál wrote:
> 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
>
> bruce barker wrote:
>> 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)
>>
>> Kornél Pál wrote:
>>> 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
>>>
>>> Brett Ossman wrote:
>>>> 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

 
Reply With Quote
 
Andrew Morton
Guest
Posts: n/a
 
      06-10-2009
Brett Ossman wrote:
> 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/libr...m.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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List of free web site design, web site backgrounds, web site layoutsresources cyber XML 1 12-25-2007 11:48 PM
Free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-24-2007 04:26 PM
List of free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-21-2007 03:47 PM
List of free web site design, web site backgrounds, web site layoutsweb sites cyber HTML 1 12-19-2007 09:07 AM
Create a web site, not default web site mike kim ASP .Net 2 08-19-2003 11:26 PM



Advertisments