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.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim conn As New SqlClient.SqlConnection _
("Server=localhost;" & "DataBase=Northwind;" & _
"Integrated Security=SSPI")
Dim cmd As New SqlClient.SqlCommand("SELECT FileName, PictureID
FROM Picture", conn)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim dsPictures As New DataSet
da.Fill(dsPictures)
Me.Image1.Visible = False
ListBox1.AutoPostBack = True
Try
ListBox1.DataSource = dsPictures.Tables(0)
ListBox1.DataTextField = "FileName"
ListBox1.DataValueField = "PictureID"
ListBox1.DataBind()
Catch sqlExc As SqlClient.SqlException
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_SelectedIndexChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
Session.Item("img") = ListBox1.SelectedItem.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.EventArgs) Handles MyBase.Load
Dim conn As New SqlClient.SqlConnection("Server=localhost;" & _
"DataBase=Northwind;" & "Integrated Security=SSPI")
Dim sqlstr As String = _
String.Format("SELECT Picture FROM Picture WHERE (PictureID = {0})",
CInt(Session.Item("img")))
Dim cmd As New SqlClient.SqlCommand(sqlstr, conn)
conn.Open()
Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader()
rdr.Read()
Response.BinaryWrite(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
GetThumbnailImage 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.WriteFile 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