Small Basic > Curriculum > Online > Lesson 2.6: Flickr, ImageList, and Network Objects
In this lesson, you will learn how to:
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.
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:
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.
Let’s look at another object that you can use to add specific images to your Small Basic program.
This is the ImageList object.
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)
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.
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.
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)
In this case, the text window displays the HTML code of the Web page, “http: //www.microsoft.com/”.
Congratulations!
Now you know how to:
Write a program that performs the following operations:
To see the answers to these questions, go to the Answer Key page.
Next Lesson
Ed Price - MSFT edited Revision 2. Comment: PPD section
Fernando Lugão Veltem edited Revision 1. Comment: added toc