ASP.net Ques: Image Retrieval

N

news.microsoft.com

Hi, I am pretty new to ASP.net

I want to do the following but I have been unable to find good info/ or
sample code on it; please help;

- retrieve a gif/jpeg image using ASP.net from another site

- using ASP.net (Visual Basic.net or C#) code I want to edit the image by
superimposing a smaller image on the lower right hand corner

- then display the image to the user

- if possible, store the image to MySQL server

Thank you in advance. and please be as detail as you like.

Joe.
 
C

Cor Ligthert

Hi,

Maybe you can use this sample that I once made how you can do it. This uses
images in a database, you can as well choise for using paths. Where in my
opinion this one is better for securing your images.

However, when you store your paths in the database, the images can come from
everywhere. (That is a different and easier solution by the way)

\\\For the database the standard Northwind sample database.
\\\It needs 2 forms with a listbox, a picturebox and a label on form1
\\\webform1
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=(Local); DataBase=Northwind;" & _
"Integrated Security=SSPI")
Dim da As New SqlClient.SqlDataAdapter _
("SELECT FirstName, EmployeeID FROM Employees", conn)
Dim ds As New DataSet
Me.Image1.Visible = False
ListBox1.AutoPostBack = True
Try
da.Fill(ds)
ListBox1.DataSource = ds.Tables(0)
ListBox1.DataTextField = "FirstName"
ListBox1.DataValueField = "EmployeeID"
ListBox1.DataBind()
Catch sqlExc As SqlClient.SqlException
Me.Label1.Text = sqlExc.ToString
Catch exc As Exception
Me.Label1.Text = exc.ToString
End Try
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/TestWebImage/WebForm2.aspx"
'This is the location of the aspx files
End Sub
///
\\\webform2 watch that the Memstream, which is for Northwind
'the normal code is as well in it.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlClient.SqlConnection("Server=(Local);" & _
"DataBase=Northwind; Integrated Security=SSPI")
Dim sqlstr As String = _
String.Format("SELECT Photo FROM Employees WHERE (EmployeeID =
{0})", _
CInt(Session.Item("img")))
Dim cmd As New SqlClient.SqlCommand(sqlstr, conn)
conn.Open()
Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader()
rdr.Read()
Dim arrImage() As Byte = DirectCast(rdr.Item("Photo"), Byte())
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Dim ms1 As New System.IO.MemoryStream(arrImage)
'The one above is for normal purpose, however Northwint has a
strange format
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ms1 As New System.IO.MemoryStream(arrImage, 78,
arrImage.Length - 78)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim origimage As System.drawing.Image =
System.Drawing.Image.FromStream(ms1)
Dim PThumbnail As System.drawing.Image
PThumbnail = origimage.GetThumbnailImage(100, 100, Nothing, New
IntPtr)
Dim ms2 As New System.IO.MemoryStream
PThumbnail.Save(ms2, Imaging.ImageFormat.Bmp)
arrImage = ms2.GetBuffer
Response.BinaryWrite(arrImage)
rdr.Close()
conn.Close()
End Sub
///

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top