2 Replies - 10024 Views - Last Post: 11 October 2008 - 11:06 PM Rate Topic: -----

#1 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Any ideas for displaying a image from url into listview?

Post icon  Posted 11 October 2008 - 08:56 PM

Hey

Okay, so I had this idea for the program Web Spydr even though it's on hold. But I'm testing some new things. I thought it would be possilbe to be able to add a url image into a image list then assign the listview control with the image list.

Here's the code: basically there's a testbox control, a list viewcontrol, a button control and a web browser control. I'm using httpgetresponse from system.net

So, the test is to type in a url tha thas a image such as http://www.sillypsac.../sillyimage.jpg you know? Then add it into the image list that's created with a New instance then transfer the image from the image list into the list view box. Also, you can see that I took some samples from Web Spydr and did the same thing when it requests the image height etc..


Dim ImgList As New ImageList

		Dim ImageURL As String
		ImageURL = TextBox1.Text



		WebBrowser1.Navigate(ImageURL)

		Dim img = Net.HttpWebRequest.Create(TextBox1.Text).GetResponse.GetResponseStream

		ImgList.Images.Add("test", System.Drawing.Bitmap.FromStream(Net.HttpWebRequest.Create(TextBox1.Text).GetResponse.GetResponseStream))


		ListView1.Items.Add(TextBox1.Text)
		ListView1.Items.Item(0).ImageKey = img.ToString



The error says

Quote

A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.dll


Any suggestios? Thanks guys!

-3v0lut10n aka Pau1

Is This A Good Question/Topic? 0
  • +

Replies To: Any ideas for displaying a image from url into listview?

#2 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Any ideas for displaying a image from url into listview?

Posted 11 October 2008 - 09:34 PM

okay, so I tried to see if it will load from a local file. so I made a image list loaded a image into it. I made a button to do the action of loading the image from the image list onto the listview box. So, it works but doesn't show the image. Also, i give the listviewbox a largeimagelistcollection and set it as imagelist1.

Here's the coding:

 Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
		Dim ImgList As New ImageList
		Try
			' ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))

			ListView1.LargeImageList.Images.Add(ImageList1.Images.Item(0))
			Label1.Text = "Image has successfully added to image list!"

			ListView1.Items.Add("testing").ImageList.Images.Item(0).ToString()






		Catch ex As Exception
			Label1.Text = "Image has failed being added to image list!"

		End Try

	End Sub



It catches if there was an exception thrown out and there was not. The label1 reads that it was successful. Now, this is just a test-so I'm not really that concerned about hwo it looks or whatever. I gotta feeling I missed something really important for this to work though. :blink:
Was This Post Helpful? 0
  • +
  • -

#3 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Any ideas for displaying a image from url into listview?

Posted 11 October 2008 - 11:06 PM

Good news -

I got it to work! :)

the correct code was if anyone wanted to use this code sample they can!


	Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


		Dim ImageURL As String
		ImageURL = TextBox1.Text



		WebBrowser1.Navigate(ImageURL)

		Try
			ImgList.Images.Add(Bitmap.FromStream(System.Net.HttpWebRequest.Create(TextBox1.Text).GetResponse.GetResponseStream))
			Label1.Text = "Successfully added image from website url!"
			ListView1.Items.Add("SexyPicture" & nIndex, nIndex)
			nIndex = nIndex + 1


		Catch ex As Exception
			Label1.Text = "Failed adding image from website url."

		End Try



	End Sub


-3v0lut10n
Was This Post Helpful? 1

Page 1 of 1