Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Question on rendering images from SQL database

Reply
Thread Tools

Question on rendering images from SQL database

 
 
Blasting Cap
Guest
Posts: n/a
 
      10-25-2006

I am using the following code to pull an image out of a database &
display it on a web page.

Dim data As New data
Dim sID As String = Request.Params("itemID")
Dim sqlConnection As New SqlConnection(data.connectionString)
Dim sqlCom As New SqlCommand("Select Data, Type From tblImageStorage
Where (Story_ID='" & sID & "')", sqlConnection)
Dim sqlDataReader As SqlDataReader
sqlConnection.Open()
sqlDataReader = sqlCom.ExecuteReader
sqlDataReader.Read()
Dim byteArray As Byte() = CType(sqlDataReader("Data"), Byte())
Dim mstream As System.IO.MemoryStream = New
System.IO.MemoryStream(byteArray, 0, byteArray.Length)
Dim dbImage As System.Drawing.Image =
System.Drawing.Image.FromStream(New System.IO.MemoryStream(byteArray))
Dim bmp As Bitmap = New Bitmap(dbImage)
Dim scale As Single = 300.0F / System.Math.Max(0, bmp.Width)
Dim thumbnailImage As System.Drawing.Image =
bmp.GetThumbnailImage(CType((bmp.Width * scale), Integer),
CType((bmp.Height * scale), Integer), Nothing, System.IntPtr.Zero)
thumbnailImage.Save(Context.Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
sqlConnection.Close()


It works fine & displays the image fine.

However, the application I have needs to have the ability to read a
story out of the same sql database & display it. It seems that I can
only do one thing.

How can you display the graphic read from a SQL database AND the story
associated with it on the same page?

As an added "oddity" I have noticed that on the rendered page, that
"View Source" is not available from the file/edit/view menu. Do not
know if that means anything or not.

Any help appreciated.

BC



 
Reply With Quote
 
 
 
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      10-25-2006
you only get one item per response. if you to return text and an image (at
least with IE), you need to return html with a image tag with a reference to
the image url.if you google this newgroup for sqlserver image, you will get
details.

-- bruce (sqlwork.com)

"Blasting Cap" <(E-Mail Removed)> wrote in message
news:eyjtc4F%(E-Mail Removed)...
>
> I am using the following code to pull an image out of a database & display
> it on a web page.
>
> Dim data As New data
> Dim sID As String = Request.Params("itemID")
> Dim sqlConnection As New SqlConnection(data.connectionString)
> Dim sqlCom As New SqlCommand("Select Data, Type From tblImageStorage Where
> (Story_ID='" & sID & "')", sqlConnection)
> Dim sqlDataReader As SqlDataReader
> sqlConnection.Open()
> sqlDataReader = sqlCom.ExecuteReader
> sqlDataReader.Read()
> Dim byteArray As Byte() = CType(sqlDataReader("Data"), Byte())
> Dim mstream As System.IO.MemoryStream = New
> System.IO.MemoryStream(byteArray, 0, byteArray.Length)
> Dim dbImage As System.Drawing.Image =
> System.Drawing.Image.FromStream(New System.IO.MemoryStream(byteArray))
> Dim bmp As Bitmap = New Bitmap(dbImage)
> Dim scale As Single = 300.0F / System.Math.Max(0, bmp.Width)
> Dim thumbnailImage As System.Drawing.Image =
> bmp.GetThumbnailImage(CType((bmp.Width * scale), Integer),
> CType((bmp.Height * scale), Integer), Nothing, System.IntPtr.Zero)
> thumbnailImage.Save(Context.Response.OutputStream,
> System.Drawing.Imaging.ImageFormat.Jpeg)
> sqlConnection.Close()
>
>
> It works fine & displays the image fine.
>
> However, the application I have needs to have the ability to read a story
> out of the same sql database & display it. It seems that I can only do
> one thing.
>
> How can you display the graphic read from a SQL database AND the story
> associated with it on the same page?
>
> As an added "oddity" I have noticed that on the rendered page, that "View
> Source" is not available from the file/edit/view menu. Do not know if
> that means anything or not.
>
> Any help appreciated.
>
> BC
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
rendering images from a database ccc31807 Perl Misc 0 11-03-2009 06:09 PM
IE6 SP1 rendering vs IE6 SP2 rendering Peter Mount HTML 4 01-31-2006 08:01 AM
store Images (or any Binary Data) to a SQL Server database using VC++ Universal C++ 1 04-08-2005 10:23 AM



Advertisments