Can images be saved to Session State and retrieved?

Discussion in 'ASP .Net' started by =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 31, 2005.

  1. Hello -

    I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#) is
    there any way to temporarily save an image to a session object, and after
    running some other operations, later retrieve the image from the session
    object, convert it back to an image, and re-save it to the database?

    Thanks?
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 31, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=

    Brock Allen Guest

    Why not? Check out the Bitmap class.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hello -
    >
    > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > is there any way to temporarily save an image to a session object, and
    > after running some other operations, later retrieve the image from the
    > session object, convert it back to an image, and re-save it to the
    > database?
    >
    > Thanks?
    >
    Brock Allen, Jul 31, 2005
    #2
    1. Advertising

  3. Hi,

    Why not covert the Image to Binary and then store it in session with the Img
    format?
    Is this a bad idea?

    ++Vijay R


    "Brock Allen" wrote:

    > Why not? Check out the Bitmap class.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hello -
    > >
    > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > is there any way to temporarily save an image to a session object, and
    > > after running some other operations, later retrieve the image from the
    > > session object, convert it back to an image, and re-save it to the
    > > database?
    > >
    > > Thanks?
    > >

    >
    >
    >
    >
    =?Utf-8?B?VmlqYXk=?=, Aug 2, 2005
    #3
  4. Thanks Vijay,

    As simple as this might sound, it's taking me forever. Could you pls point
    me to some sample code?

    The sample code i find, requires that i know the size and file type of the
    image (bitmap) in the database, which i might not... I don't seem to find a
    sample which is as "simple" as your solution seems to imply.

    thanks

    "Vijay" wrote:

    > Hi,
    >
    > Why not covert the Image to Binary and then store it in session with the Img
    > format?
    > Is this a bad idea?
    >
    > ++Vijay R
    >
    >
    > "Brock Allen" wrote:
    >
    > > Why not? Check out the Bitmap class.
    > >
    > > -Brock
    > > DevelopMentor
    > > http://staff.develop.com/ballen
    > >
    > >
    > >
    > > > Hello -
    > > >
    > > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > > is there any way to temporarily save an image to a session object, and
    > > > after running some other operations, later retrieve the image from the
    > > > session object, convert it back to an image, and re-save it to the
    > > > database?
    > > >
    > > > Thanks?
    > > >

    > >
    > >
    > >
    > >
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Aug 3, 2005
    #4
  5. Thanks Brock,

    The bitmap class requires that i know that width and height of the image, to
    first declare and instantiate the bitmap. Can this be done w/out know this
    info? And, i'm also quite new at this, can you point me to some examples. I
    have not found an example which enables me to save to session state and
    retrieve. Only to save to file system... or retreive via stream with all of
    the information coming from the stream object, which is difficult for me to
    manipulate into an example that's right for me.

    thanks,

    "Brock Allen" wrote:

    > Why not? Check out the Bitmap class.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hello -
    > >
    > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > is there any way to temporarily save an image to a session object, and
    > > after running some other operations, later retrieve the image from the
    > > session object, convert it back to an image, and re-save it to the
    > > database?
    > >
    > > Thanks?
    > >

    >
    >
    >
    >
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Aug 3, 2005
    #5
  6. Hi,

    I think this should work just for converting the bitmap to a byte stream:
    --------------------------------------------------------------------
    FileStream Fs = new
    FileStream(TextBox2.Text.Trim(),FileMode.Open,FileAccess.Read);
    byte[] RawData = new byte[Fs.Length];

    Fs.Read(RawData,0,Convert.ToInt32(Fs.Length));
    Fs.Close();

    Session.Add("FileData",RawData);
    -------------------------------------------------------------------

    Now assuming that the file format is always bmp, we have to work on
    converting it back into bmp.
    will work on this :)

    ++Vijay R


    "charliewest" wrote:

    > Thanks Vijay,
    >
    > As simple as this might sound, it's taking me forever. Could you pls point
    > me to some sample code?
    >
    > The sample code i find, requires that i know the size and file type of the
    > image (bitmap) in the database, which i might not... I don't seem to find a
    > sample which is as "simple" as your solution seems to imply.
    >
    > thanks
    >
    > "Vijay" wrote:
    >
    > > Hi,
    > >
    > > Why not covert the Image to Binary and then store it in session with the Img
    > > format?
    > > Is this a bad idea?
    > >
    > > ++Vijay R
    > >
    > >
    > > "Brock Allen" wrote:
    > >
    > > > Why not? Check out the Bitmap class.
    > > >
    > > > -Brock
    > > > DevelopMentor
    > > > http://staff.develop.com/ballen
    > > >
    > > >
    > > >
    > > > > Hello -
    > > > >
    > > > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > > > is there any way to temporarily save an image to a session object, and
    > > > > after running some other operations, later retrieve the image from the
    > > > > session object, convert it back to an image, and re-save it to the
    > > > > database?
    > > > >
    > > > > Thanks?
    > > > >
    > > >
    > > >
    > > >
    > > >
    =?Utf-8?B?VmlqYXk=?=, Aug 4, 2005
    #6
  7. Hi Charlie,

    I wanted to ask,
    How is the bitmap stored in the database? as a Blob or in bytes?
    if it is stored in bytes, then I feel that Blob/Image is the better option.

    you can insert the byte array as I mentioned before in the Image field of
    the database.
    For retrieving and displaying the image, put the byte array into a stream
    and then create a bitmap file from the stream.

    ----------------------------------------------------------------------
    MemoryStream stream = new MemoryStream(RawData, true);
    stream.Write(RawData, 0, RawData.Length);

    Bitmap bmp = new Bitmap(stream);
    stream.close();
    ---------------------------------------------------------------------

    Hope this helped

    ++Vijay R


    "Vijay" wrote:

    > Hi,
    >
    > I think this should work just for converting the bitmap to a byte stream:
    > --------------------------------------------------------------------
    > FileStream Fs = new
    > FileStream(TextBox2.Text.Trim(),FileMode.Open,FileAccess.Read);
    > byte[] RawData = new byte[Fs.Length];
    >
    > Fs.Read(RawData,0,Convert.ToInt32(Fs.Length));
    > Fs.Close();
    >
    > Session.Add("FileData",RawData);
    > -------------------------------------------------------------------
    >
    > Now assuming that the file format is always bmp, we have to work on
    > converting it back into bmp.
    > will work on this :)
    >
    > ++Vijay R
    >
    >
    > "charliewest" wrote:
    >
    > > Thanks Vijay,
    > >
    > > As simple as this might sound, it's taking me forever. Could you pls point
    > > me to some sample code?
    > >
    > > The sample code i find, requires that i know the size and file type of the
    > > image (bitmap) in the database, which i might not... I don't seem to find a
    > > sample which is as "simple" as your solution seems to imply.
    > >
    > > thanks
    > >
    > > "Vijay" wrote:
    > >
    > > > Hi,
    > > >
    > > > Why not covert the Image to Binary and then store it in session with the Img
    > > > format?
    > > > Is this a bad idea?
    > > >
    > > > ++Vijay R
    > > >
    > > >
    > > > "Brock Allen" wrote:
    > > >
    > > > > Why not? Check out the Bitmap class.
    > > > >
    > > > > -Brock
    > > > > DevelopMentor
    > > > > http://staff.develop.com/ballen
    > > > >
    > > > >
    > > > >
    > > > > > Hello -
    > > > > >
    > > > > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > > > > is there any way to temporarily save an image to a session object, and
    > > > > > after running some other operations, later retrieve the image from the
    > > > > > session object, convert it back to an image, and re-save it to the
    > > > > > database?
    > > > > >
    > > > > > Thanks?
    > > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    =?Utf-8?B?VmlqYXk=?=, Aug 4, 2005
    #7
  8. Vijay,

    First, i really appreciate your help sticking with this. I think i'm almost
    there, but the examples i find (and that you provide) assume i pull the image
    directly from the Web Form, and save the image to the Session State, and
    then, pull the image from the session state. Where and how does the database
    fit in?

    I've been trying to do the following with zero luck:

    byte[] RawData = new
    byte[Convert.ToInt32(ds.Tables["Client"].Rows[0]["ImageSize"])];
    MemoryStream stream = new MemoryStream(ds.Tables["Client"].Rows[0]["Image"],
    FileMode.Open, FileAccess.Read);
    Fs.Read(RawData, 0, Convert.ToInt32(Fs.Length));
    Fs.Close();
    Session["ImageByte"] = RawData;

    And then....

    Byte[] RawData = new byte[Convert.ToInt32(Session["ImageSize"].ToString())];
    MemoryStream stream = new MemoryStream(RawData, true);
    stream.Write(RawData, 0, RawData.Length);
    Bitmap bmp = new Bitmap(stream);
    stream.Close();

    This is really going nowhere... i really am not catching how this conversion
    between images, bytes and bitmaps is working....

    If you could provide any insight on how the image is somehow saved to the a
    session state var directly from the database, and how this is read from a
    session state var... (which i think you've already provide in a former
    response) that would be frankly amazing...

    thanks,

    "Vijay" wrote:

    > Hi Charlie,
    >
    > I wanted to ask,
    > How is the bitmap stored in the database? as a Blob or in bytes?
    > if it is stored in bytes, then I feel that Blob/Image is the better option.
    >
    > you can insert the byte array as I mentioned before in the Image field of
    > the database.
    > For retrieving and displaying the image, put the byte array into a stream
    > and then create a bitmap file from the stream.
    >
    > ----------------------------------------------------------------------
    > MemoryStream stream = new MemoryStream(RawData, true);
    > stream.Write(RawData, 0, RawData.Length);
    >
    > Bitmap bmp = new Bitmap(stream);
    > stream.close();
    > ---------------------------------------------------------------------
    >
    > Hope this helped
    >
    > ++Vijay R
    >
    >
    > "Vijay" wrote:
    >
    > > Hi,
    > >
    > > I think this should work just for converting the bitmap to a byte stream:
    > > --------------------------------------------------------------------
    > > FileStream Fs = new
    > > FileStream(TextBox2.Text.Trim(),FileMode.Open,FileAccess.Read);
    > > byte[] RawData = new byte[Fs.Length];
    > >
    > > Fs.Read(RawData,0,Convert.ToInt32(Fs.Length));
    > > Fs.Close();
    > >
    > > Session.Add("FileData",RawData);
    > > -------------------------------------------------------------------
    > >
    > > Now assuming that the file format is always bmp, we have to work on
    > > converting it back into bmp.
    > > will work on this :)
    > >
    > > ++Vijay R
    > >
    > >
    > > "charliewest" wrote:
    > >
    > > > Thanks Vijay,
    > > >
    > > > As simple as this might sound, it's taking me forever. Could you pls point
    > > > me to some sample code?
    > > >
    > > > The sample code i find, requires that i know the size and file type of the
    > > > image (bitmap) in the database, which i might not... I don't seem to find a
    > > > sample which is as "simple" as your solution seems to imply.
    > > >
    > > > thanks
    > > >
    > > > "Vijay" wrote:
    > > >
    > > > > Hi,
    > > > >
    > > > > Why not covert the Image to Binary and then store it in session with the Img
    > > > > format?
    > > > > Is this a bad idea?
    > > > >
    > > > > ++Vijay R
    > > > >
    > > > >
    > > > > "Brock Allen" wrote:
    > > > >
    > > > > > Why not? Check out the Bitmap class.
    > > > > >
    > > > > > -Brock
    > > > > > DevelopMentor
    > > > > > http://staff.develop.com/ballen
    > > > > >
    > > > > >
    > > > > >
    > > > > > > Hello -
    > > > > > >
    > > > > > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > > > > > is there any way to temporarily save an image to a session object, and
    > > > > > > after running some other operations, later retrieve the image from the
    > > > > > > session object, convert it back to an image, and re-save it to the
    > > > > > > database?
    > > > > > >
    > > > > > > Thanks?
    > > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Aug 7, 2005
    #8
  9. Hi Charlie,

    Okay I thought I had explained that, must have missed it somewhere.
    here is the code to retrieve the image from the database.
    Assuming that the column in the database table is defined as Image [image]
    NULL in the table "Table1".

    ---------------------------------------------------------------------------------------------
    //Retrieve Image from database
    string strCmd = String.Format("SELECT Image FROM Table1 WHERE id = '1'",
    SqlCommand Sqlcmd = new SqlCommand(strCmd, sqlConn);

    byte[] bytImg = (byte[])Sqlcmd.ExecuteScalar();

    //Store retrieved image in session

    Session.Add("RawData",bytImg)

    //Creating memory stream with the raw image data
    System.IO.MemoryStream MemStrm = new System.IO.MemoryStream(bytImg, true);
    MemStrm .Write(bytImg, 0, bytImg.Length);

    //creating bitmap with the memory stream
    Bitmap bmp = new Bitmap(MemStrm);
    MemStrm.close();

    ------------------------------------------------------------------------------------------------
    Hope this helped.

    Regarding your code, I think you are missing something.
    Firstly you created a byte array "RawData" filled it with the contents of
    the dataset, where the col name was Imagesize. ->Now why is the image size a
    byte? and why is it stored in the database? (okay giving you that you need
    the image size)
    Secondly you created a memory stream from another col of the dataset which
    seems to be the Image. ->the image if stored in the database (in bytes)
    should be retrieved to the byte array and then put into a memory stream.
    Next you have used the file stream to read the "Rawdata" which now contains
    the Image Size. -> why do you need a file stream to read the byte array? also
    the byte array contains the image size!
    lastly you are storing the image size (RawData) in the session ->assuming
    you need the file size in the session, so what happened to the image in byte
    form which was to be stored in the session? and which was in the memory
    stream?

    I understand what you want, but your code seems wrong or probably I am
    missing something.
    anyway try the code I gave you.
    --
    --Vijay R


    "charliewest" wrote:

    > Vijay,
    >
    > First, i really appreciate your help sticking with this. I think i'm almost
    > there, but the examples i find (and that you provide) assume i pull the image
    > directly from the Web Form, and save the image to the Session State, and
    > then, pull the image from the session state. Where and how does the database
    > fit in?
    >
    > I've been trying to do the following with zero luck:
    >
    > byte[] RawData = new
    > byte[Convert.ToInt32(ds.Tables["Client"].Rows[0]["ImageSize"])];
    > MemoryStream stream = new MemoryStream(ds.Tables["Client"].Rows[0]["Image"],
    > FileMode.Open, FileAccess.Read);
    > Fs.Read(RawData, 0, Convert.ToInt32(Fs.Length));
    > Fs.Close();
    > Session["ImageByte"] = RawData;
    >
    > And then....
    >
    > Byte[] RawData = new byte[Convert.ToInt32(Session["ImageSize"].ToString())];
    > MemoryStream stream = new MemoryStream(RawData, true);
    > stream.Write(RawData, 0, RawData.Length);
    > Bitmap bmp = new Bitmap(stream);
    > stream.Close();
    >
    > This is really going nowhere... i really am not catching how this conversion
    > between images, bytes and bitmaps is working....
    >
    > If you could provide any insight on how the image is somehow saved to the a
    > session state var directly from the database, and how this is read from a
    > session state var... (which i think you've already provide in a former
    > response) that would be frankly amazing...
    >
    > thanks,
    >
    > "Vijay" wrote:
    >
    > > Hi Charlie,
    > >
    > > I wanted to ask,
    > > How is the bitmap stored in the database? as a Blob or in bytes?
    > > if it is stored in bytes, then I feel that Blob/Image is the better option.
    > >
    > > you can insert the byte array as I mentioned before in the Image field of
    > > the database.
    > > For retrieving and displaying the image, put the byte array into a stream
    > > and then create a bitmap file from the stream.
    > >
    > > ----------------------------------------------------------------------
    > > MemoryStream stream = new MemoryStream(RawData, true);
    > > stream.Write(RawData, 0, RawData.Length);
    > >
    > > Bitmap bmp = new Bitmap(stream);
    > > stream.close();
    > > ---------------------------------------------------------------------
    > >
    > > Hope this helped
    > >
    > > ++Vijay R
    > >
    > >
    > > "Vijay" wrote:
    > >
    > > > Hi,
    > > >
    > > > I think this should work just for converting the bitmap to a byte stream:
    > > > --------------------------------------------------------------------
    > > > FileStream Fs = new
    > > > FileStream(TextBox2.Text.Trim(),FileMode.Open,FileAccess.Read);
    > > > byte[] RawData = new byte[Fs.Length];
    > > >
    > > > Fs.Read(RawData,0,Convert.ToInt32(Fs.Length));
    > > > Fs.Close();
    > > >
    > > > Session.Add("FileData",RawData);
    > > > -------------------------------------------------------------------
    > > >
    > > > Now assuming that the file format is always bmp, we have to work on
    > > > converting it back into bmp.
    > > > will work on this :)
    > > >
    > > > ++Vijay R
    > > >
    > > >
    > > > "charliewest" wrote:
    > > >
    > > > > Thanks Vijay,
    > > > >
    > > > > As simple as this might sound, it's taking me forever. Could you pls point
    > > > > me to some sample code?
    > > > >
    > > > > The sample code i find, requires that i know the size and file type of the
    > > > > image (bitmap) in the database, which i might not... I don't seem to find a
    > > > > sample which is as "simple" as your solution seems to imply.
    > > > >
    > > > > thanks
    > > > >
    > > > > "Vijay" wrote:
    > > > >
    > > > > > Hi,
    > > > > >
    > > > > > Why not covert the Image to Binary and then store it in session with the Img
    > > > > > format?
    > > > > > Is this a bad idea?
    > > > > >
    > > > > > ++Vijay R
    > > > > >
    > > > > >
    > > > > > "Brock Allen" wrote:
    > > > > >
    > > > > > > Why not? Check out the Bitmap class.
    > > > > > >
    > > > > > > -Brock
    > > > > > > DevelopMentor
    > > > > > > http://staff.develop.com/ballen
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > > > Hello -
    > > > > > > >
    > > > > > > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > > > > > > is there any way to temporarily save an image to a session object, and
    > > > > > > > after running some other operations, later retrieve the image from the
    > > > > > > > session object, convert it back to an image, and re-save it to the
    > > > > > > > database?
    > > > > > > >
    > > > > > > > Thanks?
    > > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    =?Utf-8?B?VmlqYXk=?=, Aug 8, 2005
    #9
  10. Vijay,

    First, thanks a ton for your help. This has not been fun i know. I've
    managed to figure it out thanks to you. I don't know what i was trying to do
    before so your comments are all well taken, but i've just followed what
    you've suggested. There's still one thing i cannot do, but it's no longer an
    issue: I can now pull the image from the db, and save to the session state,
    as well as convert to a bitmap. But i still cannot pull the image from the
    session state object and convert to bitmap. there's clearly something that
    i'm missing... here's how my code that works looks:

    //Retrieve Image from database
    string strCmd = String.Format("SELECT Image FROM mClient WHERE (ClientId = "
    + Session["iClientId"].ToString() + ")");
    using (SqlConnection cn = utils.GetConnection())
    {
    cn.Open();
    SqlCommand Sqlcmd = new SqlCommand(strCmd, cn);
    byte[] bytImg = (byte[])Sqlcmd.ExecuteScalar();

    //Creating memory stream with the raw image data
    System.IO.MemoryStream MemStrm = new System.IO.MemoryStream(bytImg, true);
    MemStrm.Write(bytImg, 0, bytImg.Length);

    //creating bitmap with the memory stream
    Bitmap bmp = new Bitmap(MemStrm);
    MemStrm.Close();

    myData = bytImg;

    cn.Close();
    }

    Thanks agian!

    "Vijay" wrote:

    > Hi Charlie,
    >
    > Okay I thought I had explained that, must have missed it somewhere.
    > here is the code to retrieve the image from the database.
    > Assuming that the column in the database table is defined as Image [image]
    > NULL in the table "Table1".
    >
    > ---------------------------------------------------------------------------------------------
    > //Retrieve Image from database
    > string strCmd = String.Format("SELECT Image FROM Table1 WHERE id = '1'",
    > SqlCommand Sqlcmd = new SqlCommand(strCmd, sqlConn);
    >
    > byte[] bytImg = (byte[])Sqlcmd.ExecuteScalar();
    >
    > //Store retrieved image in session
    >
    > Session.Add("RawData",bytImg)
    >
    > //Creating memory stream with the raw image data
    > System.IO.MemoryStream MemStrm = new System.IO.MemoryStream(bytImg, true);
    > MemStrm .Write(bytImg, 0, bytImg.Length);
    >
    > //creating bitmap with the memory stream
    > Bitmap bmp = new Bitmap(MemStrm);
    > MemStrm.close();
    >
    > ------------------------------------------------------------------------------------------------
    > Hope this helped.
    >
    > Regarding your code, I think you are missing something.
    > Firstly you created a byte array "RawData" filled it with the contents of
    > the dataset, where the col name was Imagesize. ->Now why is the image size a
    > byte? and why is it stored in the database? (okay giving you that you need
    > the image size)
    > Secondly you created a memory stream from another col of the dataset which
    > seems to be the Image. ->the image if stored in the database (in bytes)
    > should be retrieved to the byte array and then put into a memory stream.
    > Next you have used the file stream to read the "Rawdata" which now contains
    > the Image Size. -> why do you need a file stream to read the byte array? also
    > the byte array contains the image size!
    > lastly you are storing the image size (RawData) in the session ->assuming
    > you need the file size in the session, so what happened to the image in byte
    > form which was to be stored in the session? and which was in the memory
    > stream?
    >
    > I understand what you want, but your code seems wrong or probably I am
    > missing something.
    > anyway try the code I gave you.
    > --
    > --Vijay R
    >
    >
    > "charliewest" wrote:
    >
    > > Vijay,
    > >
    > > First, i really appreciate your help sticking with this. I think i'm almost
    > > there, but the examples i find (and that you provide) assume i pull the image
    > > directly from the Web Form, and save the image to the Session State, and
    > > then, pull the image from the session state. Where and how does the database
    > > fit in?
    > >
    > > I've been trying to do the following with zero luck:
    > >
    > > byte[] RawData = new
    > > byte[Convert.ToInt32(ds.Tables["Client"].Rows[0]["ImageSize"])];
    > > MemoryStream stream = new MemoryStream(ds.Tables["Client"].Rows[0]["Image"],
    > > FileMode.Open, FileAccess.Read);
    > > Fs.Read(RawData, 0, Convert.ToInt32(Fs.Length));
    > > Fs.Close();
    > > Session["ImageByte"] = RawData;
    > >
    > > And then....
    > >
    > > Byte[] RawData = new byte[Convert.ToInt32(Session["ImageSize"].ToString())];
    > > MemoryStream stream = new MemoryStream(RawData, true);
    > > stream.Write(RawData, 0, RawData.Length);
    > > Bitmap bmp = new Bitmap(stream);
    > > stream.Close();
    > >
    > > This is really going nowhere... i really am not catching how this conversion
    > > between images, bytes and bitmaps is working....
    > >
    > > If you could provide any insight on how the image is somehow saved to the a
    > > session state var directly from the database, and how this is read from a
    > > session state var... (which i think you've already provide in a former
    > > response) that would be frankly amazing...
    > >
    > > thanks,
    > >
    > > "Vijay" wrote:
    > >
    > > > Hi Charlie,
    > > >
    > > > I wanted to ask,
    > > > How is the bitmap stored in the database? as a Blob or in bytes?
    > > > if it is stored in bytes, then I feel that Blob/Image is the better option.
    > > >
    > > > you can insert the byte array as I mentioned before in the Image field of
    > > > the database.
    > > > For retrieving and displaying the image, put the byte array into a stream
    > > > and then create a bitmap file from the stream.
    > > >
    > > > ----------------------------------------------------------------------
    > > > MemoryStream stream = new MemoryStream(RawData, true);
    > > > stream.Write(RawData, 0, RawData.Length);
    > > >
    > > > Bitmap bmp = new Bitmap(stream);
    > > > stream.close();
    > > > ---------------------------------------------------------------------
    > > >
    > > > Hope this helped
    > > >
    > > > ++Vijay R
    > > >
    > > >
    > > > "Vijay" wrote:
    > > >
    > > > > Hi,
    > > > >
    > > > > I think this should work just for converting the bitmap to a byte stream:
    > > > > --------------------------------------------------------------------
    > > > > FileStream Fs = new
    > > > > FileStream(TextBox2.Text.Trim(),FileMode.Open,FileAccess.Read);
    > > > > byte[] RawData = new byte[Fs.Length];
    > > > >
    > > > > Fs.Read(RawData,0,Convert.ToInt32(Fs.Length));
    > > > > Fs.Close();
    > > > >
    > > > > Session.Add("FileData",RawData);
    > > > > -------------------------------------------------------------------
    > > > >
    > > > > Now assuming that the file format is always bmp, we have to work on
    > > > > converting it back into bmp.
    > > > > will work on this :)
    > > > >
    > > > > ++Vijay R
    > > > >
    > > > >
    > > > > "charliewest" wrote:
    > > > >
    > > > > > Thanks Vijay,
    > > > > >
    > > > > > As simple as this might sound, it's taking me forever. Could you pls point
    > > > > > me to some sample code?
    > > > > >
    > > > > > The sample code i find, requires that i know the size and file type of the
    > > > > > image (bitmap) in the database, which i might not... I don't seem to find a
    > > > > > sample which is as "simple" as your solution seems to imply.
    > > > > >
    > > > > > thanks
    > > > > >
    > > > > > "Vijay" wrote:
    > > > > >
    > > > > > > Hi,
    > > > > > >
    > > > > > > Why not covert the Image to Binary and then store it in session with the Img
    > > > > > > format?
    > > > > > > Is this a bad idea?
    > > > > > >
    > > > > > > ++Vijay R
    > > > > > >
    > > > > > >
    > > > > > > "Brock Allen" wrote:
    > > > > > >
    > > > > > > > Why not? Check out the Bitmap class.
    > > > > > > >
    > > > > > > > -Brock
    > > > > > > > DevelopMentor
    > > > > > > > http://staff.develop.com/ballen
    > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > > > > > Hello -
    > > > > > > > >
    > > > > > > > > I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#)
    > > > > > > > > is there any way to temporarily save an image to a session object, and
    > > > > > > > > after running some other operations, later retrieve the image from the
    > > > > > > > > session object, convert it back to an image, and re-save it to the
    > > > > > > > > database?
    > > > > > > > >
    > > > > > > > > Thanks?
    > > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > > > >
    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Aug 10, 2005
    #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. shamanthakamani
    Replies:
    1
    Views:
    3,488
    Natty Gur
    Nov 20, 2003
  2. Not Liking Dot Net Today
    Replies:
    0
    Views:
    607
    Not Liking Dot Net Today
    Apr 21, 2004
  3. Maciek
    Replies:
    0
    Views:
    8,242
    Maciek
    Sep 15, 2005
  4. jnickfl1
    Replies:
    0
    Views:
    580
    jnickfl1
    Sep 18, 2006
  5. archana
    Replies:
    0
    Views:
    341
    archana
    Mar 13, 2007
Loading...

Share This Page