• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Display image from a database ...

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Display image from a database ...

    ... without using the <img src="DisplayImage.aspx?imageID=1" ... /> trick?

    Basically I am looking for the ASP.Net equivalent of the PictureBox control available to Winforms, as I already have a array of bytes as a property on my Image entity that I want to bind to, including alt tags, etc.... this isnt possible with the seperate page method that returns binary data... and is not really efficient as I already have the binary data available to me...

    Any suggestions guys?
    Vieze Oude Man

    #2
    Originally posted by mcquiggd
    ... without using the <img src="DisplayImage.aspx?imageID=1" ... /> trick?

    Basically I am looking for the ASP.Net equivalent of the PictureBox control available to Winforms, as I already have a array of bytes as a property on my Image entity that I want to bind to, including alt tags, etc.... this isnt possible with the seperate page method that returns binary data... and is not really efficient as I already have the binary data available to me...

    Any suggestions guys?
    i guess you'd have to create an actual png or jpg image from the byte array, save it to disk and set the src of the image tag to the temp file, every day/week (dependant on usage) clean up the temp images. This is what chart fx etc do when they render their dynamic graphs
    whats the lowest you can do this for?

    Comment


      #3
      Hi Hank (hope your problems are in hand)...

      Iv'e seen controls that claim to allow binding to directly to a Bitmap - in fact I have one that a guy wrote that uses session store the bitmp but it still streams it into the browser. Writing the data to a temp directory then specifying a unique id for its filename is possible, but a bit cludgy....

      Others seem to use HTTP handlers, intercept requests for images, and then stream the data back.... e.g.

      http://msdn.microsoft.com/msdnmag/is...4/CuttingEdge/

      But, basically, I have all the data I need in an Image class, and it includes ALT tags that have to be included with the image for compliance reasons...

      I don't really want to retrive the image twice, or store it in session / cache if I can avoid it...

      Ho hum, might have buy a third party component!
      Vieze Oude Man

      Comment


        #4
        Originally posted by mcquiggd
        Hi Hank (hope your problems are in hand)...

        Iv'e seen controls that claim to allow binding to directly to a Bitmap - in fact I have one that a guy wrote that uses session store the bitmp but it still streams it into the browser. Writing the data to a temp directory then specifying a unique id for its filename is possible, but a bit cludgy....

        Others seem to use HTTP handlers, intercept requests for images, and then stream the data back.... e.g.

        http://msdn.microsoft.com/msdnmag/is...4/CuttingEdge/

        But, basically, I have all the data I need in an Image class, and it includes ALT tags that have to be included with the image for compliance reasons...

        I don't really want to retrive the image twice, or store it in session / cache if I can avoid it...

        Ho hum, might have buy a third party component!

        how about an ajax call that returns your custom object and you generate a dynamic image set all it's properties in javascript clientside and display inside and add it to the dom? this way server side object creation only occurs once


        this wont work, youll have to set the content type of the xmlhttp call to image to stream the bytes back, but this wont give you your alt attributes etc.........I'd go with the temp file.....otherwise your going to be making two calls which will burden your sever more than a temp file, youll find most 3rd party components do this - dundas chart fx etc
        Last edited by HankWangford; 5 October 2006, 18:15.
        whats the lowest you can do this for?

        Comment


          #5
          I was beginning to think along similar lines, but with one slight change...

          1) Create a custom Image server control that can bind to my business object. When it renders, it outputs the alt tags, cssclass and any other attributes, and sets the src to be a request to the server with its unique identifier, and image type.

          Also, during the databinding, it places its image data (a byte[]) in the ASP.Net Cache with the relevant unique key, so it could potentially be returned to multiple clients without needing needing to rehit the DB, and do so early in the pipeline. (The Enterprise Library caches the basic Image entity for a short period so database access is also only when neccessary).

          2) Use the MS supplied HTTPModule approach that provides a lightweight interceper that can interprete requests for images, and can return a byte stream with the correct content type set - but set it to load from the ASP.Net cache. If the image is not in the cache, retrieve it from the server. (E.g, to support web farms).

          The images are typically very small - around 3k - 10k. When imported via the admin website they are resized, optimized, and stored with a thumbnail and relevant meta data. The cache would handle expiry...
          Vieze Oude Man

          Comment


            #6
            Had me stumped this one.....there is no way of doing what you want without two calls or a temp file and setting the src to the location
            whats the lowest you can do this for?

            Comment


              #7
              scott h has a nice way of implementing the handler

              http://www.codeguru.com/csharp/cshar...php/c12641__2/
              whats the lowest you can do this for?

              Comment


                #8
                Cheers Hank... looks like ill have a busy day tomorrow... demoing the project to the CEO tomorrow....
                Vieze Oude Man

                Comment


                  #9
                  Originally posted by mcquiggd
                  Cheers Hank... looks like ill have a busy day tomorrow... demoing the project to the CEO tomorrow....


                  knock him down......and earn yourself a nice rate increase
                  whats the lowest you can do this for?

                  Comment

                  Working...
                  X