Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,236 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,259 people online right now. Registration is fast and FREE... Join Now!




Any ideas for displaying a image from url into listview?

 
Reply to this topicStart new topic

Any ideas for displaying a image from url into listview?, Testing out new stuff.

EvolutionMedia
11 Oct, 2008 - 07:56 PM
Post #1

D.I.C Head
**

Joined: 11 Aug, 2008
Posts: 83



Thanked: 1 times
My Contributions
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.sillypsace.com/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..


CODE

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
User is offlineProfile CardPM
+Quote Post

EvolutionMedia
RE: Any Ideas For Displaying A Image From Url Into Listview?
11 Oct, 2008 - 08:34 PM
Post #2

D.I.C Head
**

Joined: 11 Aug, 2008
Posts: 83



Thanked: 1 times
My Contributions
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:

CODE

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.gif

User is offlineProfile CardPM
+Quote Post

EvolutionMedia
RE: Any Ideas For Displaying A Image From Url Into Listview?
11 Oct, 2008 - 10:06 PM
Post #3

D.I.C Head
**

Joined: 11 Aug, 2008
Posts: 83



Thanked: 1 times
My Contributions
Good news -

I got it to work! smile.gif

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

CODE


    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
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:33AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month