Web Site Images

Discussion in 'ASP .Net' started by Brett Ossman, Jun 8, 2009.

  1. Brett Ossman

    Brett Ossman 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
    Brett Ossman, Jun 8, 2009
    #1
    1. Advertising

  2. Brett Ossman

    sqlman Guest

    On Mon, 8 Jun 2009 12:50:01 -0700, 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


    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.
    sqlman, Jun 8, 2009
    #2
    1. Advertising

  3. On Jun 8, 9:50 pm, 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


    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);
    Alexey Smirnov, Jun 8, 2009
    #3
  4. 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
    >
    Kornél Pál, Jun 8, 2009
    #4
  5. Brett Ossman

    bruce barker Guest

    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
    bruce barker, Jun 9, 2009
    #5
  6. Brett Ossman

    Brett Ossman Guest

    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
    Brett Ossman, Jun 9, 2009
    #6
  7. >
    > 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
    Cor Ligthert[MVP], Jun 9, 2009
    #7
  8. 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
    Kornél Pál, Jun 9, 2009
    #8
  9. Brett Ossman

    bruce barker Guest

    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
    bruce barker, Jun 9, 2009
    #9
  10. 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/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
    Andrew Morton, Jun 10, 2009
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike kim
    Replies:
    2
    Views:
    521
    clintonG
    Aug 20, 2003
  2. Tiddley-Pom
    Replies:
    5
    Views:
    424
    Mark Parnell
    Oct 15, 2003
  3. mark4asp
    Replies:
    1
    Views:
    1,129
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Mar 24, 2007
  4. Replies:
    0
    Views:
    439
  5. Peter K
    Replies:
    2
    Views:
    301
    Peter K
    May 29, 2008
Loading...

Share This Page