Hi Toby,
I made a sample that works. In a nice way.
It is not a thumbnail, but that you can make using the memorystream.
It is imposible to put an image from a stream direct on a webpage.
A webpage can only show an IMG.
If you want to use a thumbnail, you first needs to convert that there is a
special class for that.
I hope this is something you need.
\\\For the database the image database sample from the Resource kit is used.
\\\It needs 2 forms with on form1 a listbox, a picturebox and a label and
on form2 nothing
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
Dim conn As New SqlClient.SqlCo nnection _
("Server=localh ost;" & "DataBase=North wind;" & _
"Integrated Security=SSPI")
Dim cmd As New SqlClient.SqlCo mmand("SELECT FileName, PictureID
FROM Picture", conn)
Dim da As New SqlClient.SqlDa taAdapter(cmd)
Dim dsPictures As New DataSet
da.Fill(dsPictu res)
Me.Image1.Visib le = False
ListBox1.AutoPo stBack = True
Try
ListBox1.DataSo urce = dsPictures.Tabl es(0)
ListBox1.DataTe xtField = "FileName"
ListBox1.DataVa lueField = "PictureID"
ListBox1.DataBi nd()
Catch sqlExc As SqlClient.SqlEx ception
Me.Label1.Text = "Database Error"
Catch exc As Exception
Me.Label1.Text = "Datbase Connection Failed!"
End Try
conn.Close()
End If
End Sub
Private Sub ListBox1_Select edIndexChanged( ByVal sender _
As System.Object, ByVal e As System.EventArg s) Handles
ListBox1.Select edIndexChanged
Session.Item("i mg") = ListBox1.Select edItem.Value
Image1.Visible = True
Image1.ImageUrl = "http://localhost/WebApplication1/WebForm2.aspx"
End Sub
///
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim conn As New SqlClient.SqlCo nnection("Serve r=localhost;" & _
"DataBase=North wind;" & "Integrated Security=SSPI")
Dim sqlstr As String = _
String.Format(" SELECT Picture FROM Picture WHERE (PictureID = {0})",
CInt(Session.It em("img")))
Dim cmd As New SqlClient.SqlCo mmand(sqlstr, conn)
conn.Open()
Dim rdr As SqlClient.SqlDa taReader = cmd.ExecuteRead er()
rdr.Read()
Response.Binary Write(CType(rdr .Item("Picture" ), Byte()))
rdr.Close()
conn.Close()
End Sub
///
I hope this helps a little bit?
Cor
In an ASP.Net application I want to convert open create a FileStream
object from a System.Drawing. Image - is this possible? I create an instance of an Image object using the FromFile method, then use the
GetThumbnailIma ge method to create a second Image. This second one is the one I want to
get a FileStream from, so that I can then use its Handle to use
Response.WriteF ile to output the thumbnail on my ASP.Net page.
Any help would be much appreciated - I realise I may not even be going
about this in the most appropriate way! Thanks in advance,
Toby Mathews