Windows Phone to get pictures in the mobile phone Image Library (4)

Source: Internet
Author: User

Prerequisites: the mobile phone and computer are not connected or the Zune software on the computer is disabled (the image library cannot be accessed when connected to the Zune software). Version 7.1

You can use the photchoosertask method and xNa method to obtain the image of the mobile phone Image Library.

Obtain photchoosertask

Reference namespace

// Reference
// Used by the photochoosertask class
Using Microsoft. Phone. tasks;
// Used by the bitmapimage class
Using system. Windows. Media. imaging;

Hide the file code:

Using system; using system. collections. generic; using system. LINQ; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using Microsoft. phone. controls; // reference // The photochoosertask class uses using Microsoft. phone. tasks; // using system is used in the bitmapimage class. windows. media. imaging; namespace choosephoto {public partial class mainpage: phoneapplicationpage {// instantiate the image selector photochoosertask photochoose = new photochoosertask (); // constructor public mainpage () {initializecomponent (); // sets the delegate event photochoose. completed + = new eventhandler <photoresult> (photochoose_completed);} // The Void photochoose_completed (Object sender, photoresult e) {If (E. taskresult = taskresult. OK) {// instantiate bitmapimage Bi = new bitmapimage (); // set bitmap source bi. setsource (E. chosenphoto); // sets the element bitmap IMG. source = Bi; txtname. content = E. originalfilename ;}} /// <summary> // button event // </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void txtname_click (Object sender, routedeventargs e) {// open the image library photochoose. show (); // knowledge point ① // whether to display the photo button photochoose. showcamera = true; // knowledge point ② // set the width of the cut area photochoose. pixelwidth = 50; // set the height of the cut area to photochoose. pixelheight = 100 ;}}}

Knowledge Point ①: attributes of the photochoosertask class. This attribute indicates whether to display the Start camera button. Generally, it is better to display and increase the image source path.

Knowledge Point ②: In general, the height and width of the captured area should be set or obtained.

 

Summary: Cropping is a major feature.

XNa Method

Reference namespace

// Reference the xNa Library
Using Microsoft. xNa. Framework. Media;
// Used by the bitmapimage class
Using system. Windows. Media. imaging;

Medialibrary should be able to be translated into a media library, which contains audio, video, and images. It is a collection of all media.

Hide the file code:

Using system; using system. collections. generic; using system. LINQ; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using Microsoft. phone. controls; // reference the xNa library using Microsoft. xNa. framework. media; // using system is used in the bitmapimage class. windows. media. imaging; namespace xnachoosephoto {public partial class mainpage: phoneapplicationpage {// knowledge point ① medialibrary medial = new medialibrary (); // constructor public mainpage () {initializecomponent (); // getpic ();} // <summary> // obtain an image /// </Summary> void getpic () {// obtain all pictures in the media library picturecollection PIC = medial. pictures; If (PIC. count> 1) {bitmapimage Bi = new bitmapimage (); // knowledge point ② picture Pc = PIC [0]; bi. setsource (PC. getimage (); IMG. source = Bi; txtname. TEXT = "image name:" + PC. name + "; \ n the image album name:" + PC. album. name + "; \ n get photo shooting time" + PC. date ;}}}}

Knowledge Point ①: medialibrary is a very useful class. For example, you can obtain the songs in it.

 

 MediaLibrary mediaL = new MediaLibrary();            SongCollection sc = mediaL.Songs;            if (sc.Count > 1)            {                Song s = sc[0];                MediaPlayer.Play(s);            }

Knowledge Point ②: Some attributes or methods of the picture class will be used, such as the phase set of the current image, whether the phase set will also contain the phase set, and the name and time of the phase set.

 Summary: The overall idea is to strip from the collection step by step, and the media library (audio and video, image) -------, image set ------, image -----, and image-related attributes; I forgot from which blogger to see that if the class in xNa is used, the application cannot be submitted through

After running:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.