Bài giảng Lập trình cho thiết bị di động Windows Phone - Trần Duy Thanh - Working with the phone camera and photos

1. Launchers and Choosers

2. Search extensibility

3. Acquiring a single photo

4. Working with the media library

5. Capturing photos

6. Extending the Photos Hub

7. Lenses

8. Sharing photos

 

pptx38 trang | Chuyên mục: Windows Phone | Chia sẻ: dkS00TYs | Lượt xem: 5832 | Lượt tải: 2download
Tóm tắt nội dung Bài giảng Lập trình cho thiết bị di động Windows Phone - Trần Duy Thanh - Working with the phone camera and photos, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
og with which the user can change the device’s connection settings EmailComposeTask Composes a new email MapDownloaderTask Provides a mechanism for the user to download maps for offline use MapUpdaterTask Provides a mechanism for the user to update map data he has previously downloaded for offline use. 5 1. Launchers and Choosers Launchers Task Description MapsDirectionsTask Launches the Maps app, specifying a starting and/or ending location, for which driving or walking directions are displayed (identical to BingMapsDirectionsTask). MapsTask Launches the Maps app centered at the specified or current location (identical to BingMapsTask) MarketplaceDetailTask Launches the Windows Phone Store and displays the details for a specific app MarketplaceHubTask Launches the Windows Phone Store and searches for a particular type of content MarketplaceReviewTask Displays the Windows Phone Store review page for the current app MarketplaceSearchTask Launches the Windows Phone Store and displays the search results from the specified search terms. 6 1. Launchers and Choosers Launchers Task Description MediaPlayerLauncher Launches Media Player, and plays the specified media file PhoneCallTask Initiates a phone call to a specified number. SaveAppointmentTask Provides a mechanism for the user to save an appointment from your app SearchTask Launches Microsoft Bing Search with a specified search term ShareLinkTask Launches a dialog with which the user can share a link on the social networks of her choice. If the user does not have any social networks set up, the Launcher silently fails ShareMediaTask Provides a mechanism for your app to share a media item with one of the media-sharing apps on the phone 7 1. Launchers and Choosers Launchers Task Description ShareStatusTask Launches a dialog with which the user can share a status message on the social networks of her choice. If the user does not have any social networks set up, the Launcher silently fails SmsComposeTask Composes a new text message. WebBrowserTask Launches Microsoft Internet Explorer and browses to a specific URI 8 1. Launchers and Choosers Choosers Task Description AddWalletItemTask Launches the Wallet app and allows the user to add the supplied item to his wallet AddressChooserTask Launches the Contacts app with which the user can find an address. CameraCaptureTask Opens the Camera app to take a photo EmailAddressChooserTask Provides a mechanism for the user to select an email address from his Contacts List. GameInviteTask Shows the game invite screen with which the user can invite players to a multiplayer game session. PhoneNumberChooserTask Provides a mechanism for the user to select a phone number from his Contacts List 9 1. Launchers and Choosers Choosers Task Description PhotoChooserTask Provides a mechanism for the user to select an image from his Picture Gallery or take a photo SaveContactTask Launches the Contacts app with which the user can save a contact. SaveEmailAddressTask Saves an email address to an existing or new contact. SavePhoneNumberTask Saves a phone number to an existing or new contact SaveRingtoneTask Launches the Ringtones app with which the user can save a ringtone from your app to the system ringtones list 10 1. Launchers and Choosers The basic steps for using a Launcher are as follows: 1. Create an instance of the type that represents the specific Launcher feature that you want to use. 2. Set properties on the object as appropriate. 3. Invoke the Show method 11 1. Launchers and Choosers The basic steps for using a Launcher are as follows: Simple Example for SMS message: SmsComposeTask smsTask = new SmsComposeTask(); smsTask.To = "0987773061"; smsTask.Body = "Alô Năm Mới ! mới hơn năm cũ"; smsTask.Show(); 12 1. Launchers and Choosers The basic steps for using a Chooser are as follows: 1. Create an instance of the type that represents the specific Chooser feature that you want to use. It is common to declare this as a field in your page class. 2. Hook up the Completed event on the object (or provide an inline delegate or lambda), which will be invoked when the Chooser task completes. 3. Set properties on the object as appropriate. 4. Invoke the Show method. 5. In your Completed event handler or delegate, process the return value from the Chooser. 13 1. Launchers and Choosers The basic steps for using a Chooser are as follows: Simple Example for PhoneNumberChooserTask : PhoneNumberChooserTask pnChooserTask; private void Button_Click_1(object sender, RoutedEventArgs e) { pnChooserTask = new PhoneNumberChooserTask(); pnChooserTask.Completed += new EventHandler(pnChooserTask_Completed); pnChooserTask.Show(); } 14 1. Launchers and Choosers void pnChooserTask_Completed(object sender, PhoneNumberResult e) { if (e.TaskResult == TaskResult.OK) { MessageBox.Show("The phone number for " + e.DisplayName + " is " + e.PhoneNumber); PhoneCallTask phoneCallTask = new PhoneCallTask(); phoneCallTask.DisplayName = e.DisplayName; phoneCallTask.PhoneNumber = e.PhoneNumber; phoneCallTask.Show(); } } PhoneCallTask is protected by the ID_CAP_PHONEDIALER capability 15 2. Search extensibility Another way that your app can communicate with standard phone services is by extending the Bing search experience with custom behavior, integrating your app seamlessly with the search results. There are two ways by which you can extend the Bing search behavior in your apps: App Connect and App Instant Answer. With both features, you can set up your app so that it shows up in the Bing search results when the user taps the hardware Search button Please visit this link to learn more:  16 2. Search extensibility Requirement App Connect App Instant Answer WMAppManifest.xml Requires Extensions entries for each Bing category that you want to extend No specific changes required Extras.xml Required. Specifies captions to be used in the search results apps pivot item. Not used UriMapper Recommended. Allows you to re-route to a specific page on app startup. Not required Target page You can re-route to multiple different pages, depending on the search item, if you want. No option. Your app is launched as normal, with its default startup page 17 2. Search extensibility Requirement App Connect App Instant Answer Query string You should parse the incoming query string for categories and item names for which you want to provide extensions You should parse the incoming query string for the bing_query value. Search connection Bing includes your app in the search results when the user’s search matches the categories for which you registered extensions. Bing includes your app in the search results, based on whether it thinks the query is relevant to your app. 18 2. Search extensibility The App Connect extensibility model 19 2. Search extensibility The App Instant Answer extensibility model 20 3. Acquiring a single photo Many apps need to provide the option to acquire a single photo from the user, either selected from the media library or captured by the camera. Windows Phone offers built-in tasks that make this process simple: PhotoChooserTask and CameraChooserTask using Microsoft.Phone.Tasks; using System.Windows.Media.Imaging; 21 3. Acquiring a single photo PhotoChooserTask photoChooser = new PhotoChooserTask(); photoChooser.Completed += photoChooser_Completed; photoChooser.Show(); private void photoChooser_Completed(object sender, PhotoResult e) { if (e.TaskResult != TaskResult.OK) { return; } BitmapImage image = new BitmapImage(); image.SetSource(e.ChosenPhoto); myimage.Source = image; } 22 4. Working with the media library The Media Library APIs in the XNA framework facilitate deeper integration with the user’s photos collection using Microsoft.Xna.Framework.Media; Reading photos Adding new images 23 4. Working with the media library This list is populated in the OnNavigatedTo method of the AlbumListPage. All of the photo albums available on the device are found under the RootPictureAlbum of the MediaLibrary. protected override void OnNavigatedTo(NavigationEventArgs e) { using (MediaLibrary mLib = new MediaLibrary()) { mylistbox.ItemsSource = mLib.RootPictureAlbum.Albums; } } ID_CAP_MEDIALIB_PHOTO capability 24 4. Working with the media library The Pictures property returns all of the photos in the user’s library as a single collection, whereas the RootPictureAlbum property returns a collection of PictureAlbum instances, which correspond to the individual user photo albums: foreach (PictureAlbum picAlbum in mediaLibrary.RootPictureAlbum.Albums){ foreach (Picture pic in picAlbum.Pictures) { BitmapImage bitMap = new BitmapImage(); bitMap.SetSource(pic.GetImage()); Image img = new Image();//Process Image here img.Source = bitMap; } } 25 4. Working with the media library int pictureCollectionSize; PictureCollection pictureCollection; public void createPictureSlideShow() { slideshowPivot.Items.Clear(); pictureCollection = picAlbum.Pictures; pictureCollectionSize = pictureCollection.Count; for (int i = 0; i 35 7. Lenses Lenses are camera apps that can be launched directly from the built-in camera app and which naturally complement it by using the camera sensor to provide a specialized experience 36 8. Sharing photos Users don’t want to just take photos; they want to share them, too. With Windows Phone, apps can participate in this sharing flow, whether the user is explicitly sharing a photo through the ShareMediaTask or automatically uploading them to the cloud by using auto-upload 37 8. Sharing photos WMAppManifest.xml 38 8. Sharing photos protected override void OnNavigatedTo(NavigationEventArgs e) { IDictionary queryStrings = this.NavigationContext.QueryString; if (queryStrings.ContainsKey("FileId")) { MediaLibrary library = new MediaLibrary(); Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]); BitmapImage bitmapFromPhoto = new BitmapImage(); bitmapFromPhoto.SetSource(photoFromLibrary.GetPreviewImage()); image1.Source = bitmapFromPhoto; } } Coding MainPage END 39 

File đính kèm:

  • pptx3 - WORKING WITH THE PHONE_ CAMERA and PHOTOS (3t).pptx