Small Basic Curriculum: Lesson 2.6: Flickr, ImageList, and Network Objects
Small Basic > Curriculum >** **Online > Lesson 2.6: Flickr, ImageList, and Network Objects
Estimated time to complete this lesson: 1 hours
Flickr, ImageList, and Network Objects
In this lesson, you will learn how to:
- Use different operations of the Flickr object.
- Use different operations of the ImageList object.
- Use different operations of the Network object.
The Flickr Object
Flickr! You can access this online image-hosting Web site right from within your Small Basic program.
Small Basic provides the Flickr object with two operations? GetPictureOfMoment and GetRandomPicture.
http://msdn.microsoft.com/gg703228.Flickr(en-us,MSDN.10).png
Let’s explore each of these operations…
You can use the GetPictureOfMoment operation of the Flickr object to get the URL for Flickr’s picture of the moment.
You can then retrieve and display that image in your program by using the DrawImage or DrawResizedImage operations of the GraphicsWindow object.
GraphicsWindow.BackgroundColor = "Black"
Pic = Flickr.GetPictureOfMoment()
GraphicsWindow.DrawResizedImage(Pic, 0, 0, 600, 400)
This is the output you will see:
http://msdn.microsoft.com/gg703228.Flickr_object(en-us,MSDN.10).png
You can use the GetRandomPicture operation of the Flickr object to get the URL of a picture that has a tag in Flickr that you specify.
For example, you can show five landscape photos on your desktop by using the GetRandomPicture operation and specifying the tag as “landscape,” as the example shows.
For image = 1 to 5
pic = Flickr.GetRandomPicture("landscape")
Desktop.SetWallPaper(pic)
Program.Delay(10000)
EndFor
After you run the program, your desktop wallpaper changes to one of five landscape images every 10 seconds.
To use the Flickr object in Small Basic, you must be connected to the Internet.
The ImageList Object
Let’s look at another object that you can use to add specific images to your Small Basic program.
This is the ImageList object.
http://msdn.microsoft.com/gg703228.Image_List(en-us,MSDN.10).png
You can use this object to load images from a specific location and store them in memory. The ImageList object provides the following operations:
LoadImage - This operation loads the stored image from a local file or the Internet into the memory of your computer. You must specify the name or the URL of the file that you want to load.
GetHeightOfImage and GetWidthOfImage - These operations retrieve the height and width of the stored image. When you use this operation, you must specify the name of the image file.
Let’s see how you can use the various operations of the ImageList object…
Let’s look at this with an example…
ImagePath = "C:\Microsoft Small Basic\Sunset.jpg"
Image = ImageList.LoadImage(ImagePath)
Width = ImageList.GetWidthOfImage(ImagePath)
Height= ImageList.GetHeightOfImage(ImagePath)
GraphicsWindow.Width = Width
GraphicsWindow.Height= Height
GraphicsWindow.DrawImage(Image, 0, 0)
This is the output you will see:
http://msdn.microsoft.com/gg703228.Image_object(en-us,MSDN.10).png
You retrieve the height and width of the image by using the GetHeightOfImage and GetWidthOfImage operations.
You then set the size of the GraphicsWindow object to the same size as the image.
Now, you show image in the graphics window.
The Network Object
You may sometimes want to include a certain file in your Small Basic program. This file may be available on your local network or as a webpage on the Internet.
You can retrieve the required file from the network by using the Network object in Small Basic.
http://msdn.microsoft.com/gg703228.Network(en-us,MSDN.10).png
As you see, the Network object provides two operations - DownloadFile and GetWebPageContents.
Let’s learn more about these operations and how to use them…
You can use the DownloadFile operation of the Network object to download a file from the network to a temporary file on your local computer. To use this operation, you must specify the location of the file on the network.
FilePath="http://www.microsoft.com/"
DownloadFile = Network.DownloadFile(FilePath)
TextWindow.WriteLine("Downloaded File:" + DownloadFile)
The text window displays the location of the downloaded file on your computer.
You can get the contents of a webpage that you specify by using the GetWebPageContents operation of the Network object.
FilePath = "http://www.microsoft.com/"
WebPageContent = Network.GetWebPageContents(FilePath)
TextWindow.WriteLine("Page Content: ")
TextWindow.WriteLine(WebPageContent)
This is the output you will see:
http://msdn.microsoft.com/gg703228.Network_object(en-us,MSDN.10).png
In this case, the text window displays the HTML code of the Web page, “http: //www.microsoft.com/”.
Let’s Summarize…
Congratulations!
Now you know how to:
- Use different operations of the Flickr object.
- Use different operations of the ImageList object.
- Use different operations of the Network object.
Show What You Know
Write a program that performs the following operations:
- Loads 10 images of animals from Flickr.
- Sets the height and width of the graphics window to match the size of the images.
- Displays the downloaded images in the graphics window.
- Changes the image every two seconds.
To see the answers to these questions, go to the Answer Key page.