Wednesday, December 15, 2010

WPF download and save image using VB.NET

Dim myWebClient As New WebClient()
        Dim strThumb As New Uri("http://www.somesite.com/image.jpg")
        Using stream As Stream = myWebClient.OpenRead(strThumb)
        
            Using bitmap As New System.Drawing.Bitmap(stream)
                'flush and close the stream
                stream.Flush()
                stream.Close()
            
                bitmap.Save(AppDomain.CurrentDomain.BaseDirectory + "Cache\test.jpg")
            End Using
        End Using

Monday, December 6, 2010

WPF Create Menu Icon On The Fly

I needed to retrieve a remote image url and use it as a menu item in my vb.net wpf application.

Did it as so where mnuTitle is the menu item to have the icon changed.
This should work with Silverlight as well.

Dim ico As New Image
 ico.Source = New BitmapImage(New Uri("http://www.site.com/image.jpg",UriKind.RelativeOrAbsolute))
 mnuTitle.Icon = ico