How to convert Byte Array into Image Url

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pavanip
    New Member
    • Mar 2008
    • 53

    #1

    How to convert Byte Array into Image Url

    Hi,

    I am developing a simple application Image Zooming using ASP and C#.
    In that I used treeview control to display images in different levels or sizes.
    Here I am storing the images in database in byte format.
    If I click on particular image I am displaying that in Imagebutton.
    How can I get image path that is stored in database in byte format.
    I want that image path from database.
    Please anybody help me.


    Thanks in Advance
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Originally posted by pavanip
    Hi,

    I am developing a simple application Image Zooming using ASP and C#.
    In that I used treeview control to display images in different levels or sizes.
    Here I am storing the images in database in byte format.
    If I click on particular image I am displaying that in Imagebutton.
    How can I get image path that is stored in database in byte format.
    I want that image path from database.
    Please anybody help me.


    Thanks in Advance

    Convert byte array into string so now you can get image url

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by pavanip
      Hi,

      I am developing a simple application Image Zooming using ASP and C#.
      In that I used treeview control to display images in different levels or sizes.
      Here I am storing the images in database in byte format.
      If I click on particular image I am displaying that in Imagebutton.
      How can I get image path that is stored in database in byte format.
      I want that image path from database.
      Please anybody help me.


      Thanks in Advance
      You could create an ASPX page to serve up your images.
      Basically create a new ASPX page and strip out the content...so your ASPX page would look something like:

      [code=asp]
      <%@ Page Language="vb" AutoEventWireup ="false" CodeBehind="Pic ture.aspx.vb" Inherits="MyNam espace.Picture" %>
      [/code]

      Then in your Page_Load you retrieve the image from the database and write that directly to the Response stream....

      eg:
      [code=vbnet]


      'Instead of reading the file from the server, read it from your database.
      'You will have to pass a Parameter in with your query string that will let this aspx page know what your picture ID in order to retrieve the image from your database.
      Dim fs As FileStream = File.OpenRead(S erver.MapPath(" ~/Images/theImageName.jp g"))
      Dim b(fs.Length) As Byte
      For i = 0 To fs.Length - 1
      b(i) = fs.ReadByte
      Next
      fs.Close()
      'Note that I'm setting the content type to image/jpg...so now when this ASPX page is returned to the browser, it's mime type is set to image/jpg...which the browser will render as an image
      Response.Conten tType = "image/jpg"
      Response.Binary Write(b)
      [/code]

      Then for your link button you would set the image url to be aspx page serving up your image.

      eg:
      [code=vbnet]
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load

      myImageButton.I mageUrl = "Picture.as px"

      'Since you'll have to pass some ID into your picture aspx page your ImageUrl will look more like:
      'myImageButton. ImageUrl = "Picture.aspx?p icId=12345"
      End Sub
      [/code]

      -Frinny

      Comment

      Working...