MS Small Basic第七章: Fun with Shapes(玩形)(Part7: Flickr, ImageList, and Network Objects)

終於來到第七章的最後一篇了, 第七章搞了好久, 因為總共寫了七篇, 從Part1寫到Part7…

Lesson 2.6: Flickr, ImageList, and Network Objects

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.

GetPictureOfMoment() 獲得現在的這張圖片的 URL

  • 返回 : 指向某一時刻 Flickr 上圖片的檔 URL

GetRandomPicture(tag) 隨即獲得標記了特定標籤的圖片的 URL

  • tag : 請求圖片的標籤
  • 返回 : 指向 Flickr 隨機圖片的檔 URL

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.

使用 Flickr.GetPictureOfMoment() 不一定要有Flickr帳號和圖片, 我沒有使用Flickr, 還是可以抓到上面那張圖片, 不過似乎是隨機的, 看你執行程式的當下有什麼圖片被傳到Flickr上, 就會被抓下來, 補一下Flickr的官方網站: http://www.flickr.com/

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.

Flickr.GetRandomPicture(“landscape")會隨機在Flickr網站上抓取含有 “landscape" 標籤的圖片五張, 並把它們設成你的桌布, 每張圖片維持10秒:

在桌面上看解析度很差, 因為是隨機抓取, 所以不知道原來圖片的解析度或尺寸如何, 不知道能不能設定只抓取特定尺寸的圖片?

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.

LoadImage(fileNameOrUrl) 將圖像從互聯網或檔中載入到記憶體

  • fileNameOrUrl : 要載入的影像檔名。可以是一個本地檔或一個 Internet 上的 URL
  • 返回 : 返回已載入的圖像名

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.

GetWidthOfImage(imageName) 獲得存儲圖像的寬度

  • imageName : 記憶體中圖像的名稱
  • 返回 : 特定圖像的寬度

GetHeightOfImage(imageName) 獲得存儲圖像的高度

  • imageName : 記憶體中圖像的名稱
  • 返回 : 特定圖像的高度

Let’s see how you can use the various operations of the ImageList object.

GraphicsWindow.Width = Width 和 GraphicsWindow.Height = Height 把顯示視窗的長寬設成和抓下來的圖片一樣, 並且GraphicsWindow.DrawImage(Image, 0, 0)從座標(o, o)開始Draw Image, 所以出來的圖形會剛好滿滿一個視窗, 不多也不少.

從台北捷運官網抓的捷運路線圖太大張了, 有點超出我的螢幕大小……

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.

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.

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 theNetwork object.

抓檔案和網頁內容的部分可能用Python會更強大, 還是其實Small Basic也很強大, 只是我不知道…

廣告

About leeoxygen

吱吱喳喳,嚕嚕啦啦,嗯嗯啊啊.
本篇發表於 我的Small Basic學習記錄 並標籤為 , 。將永久鏈結加入書籤。

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s