PDA

View Full Version : ASP.net - CreatingDrawing.Image from database


david7777
03-11-2003, 05:32 PM
I have a database with a table of images in it.
I get the image i need from the database, but then need to create a System.Drawing.Image from the binaray data from the database. How do i do this?
ie:

'... Get image from database...
dim g as System.Drawing.Image = dbread("ImageBinaryData")
'... Continue with image handling...

("ImageBinaryData" is a field in the table)

Any solutions?

david7777
03-12-2003, 02:21 PM
I was too impacient to wait for replies so I worked it out myself...

I have the images in a table called big_images. The binary data is in a field called BinaryContent. The database name is mainBase.


Dim dbconn,sql,dbcomm,dbread
dim byteArray as byte()
dim stream as MemoryStream
dim g as System.Drawing.Image

' Create the database connection for access
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("mainBase.mdb"))
dbconn.Open()
SQL = "SELECT FileName, ContentType, BinaryContent FROM big_images WHERE FileID = " & Request.QueryString("FileID")
' Get what i need from the database
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()

' Get the dataset ready for reading
dbread.read()
' Get the binary data from the dataset
byteArray = dbread("BinaryContent")
' Create a stream to read the binary content
stream = new MemoryStream(byteArray)
' Creat the bitmap image from the stream
g = new Bitmap(stream)


If you want to see the full code including thumbnail settings go to my post of ASP.NET proportional thumbnails from database images (http://www.codingforums.com/showthread.php?s=&threadid=16177)

Hope that helps someone! :)