Original: Windows Phone 8.1 Multi Media (1): Photo
Windows Phone 8.1 Multi Media (1): Photos
Windows Phone 8.1 Multi Media (2): Video
Windows Phone 8.1 Multi Media (3): Music
(1) Taking photos
1) captureelement
Captureelement is a preview of the controls placed on the app interface:
<Grid> <captureelement x:name= "capturephotoelement"/> </Grid><Page.bottomappbar> <CommandBar> <Appbarbuttonx:name= "Btncapturephoto"Icon= "Camera"Label= "Capture"Click= "Btncapturephoto_click"/> </CommandBar></Page.bottomappbar>
2) MediaCapture
MediaCapture is an important class for controlling shooting.
First initialize the MediaCapture and set the Captureelement Source to the MediaCapture:
MediaCapture photocapture;imageencodingproperties imgencodingproperties;protected Override Async voidonnavigatedto (NavigationEventArgs e) {Capturephotoelement.source=awaitInitialize (); awaitPhotocapture.startpreviewasync ();}Private AsyncTask<mediacapture>Initialize () {photocapture=NewMediaCapture (); awaitPhotocapture.initializeasync (); PhotoCapture.VideoDeviceController.PrimaryUse=Captureuse.photo; Imgencodingproperties=Imageencodingproperties.createjpeg (); Imgencodingproperties.width=640; Imgencodingproperties.height=480; returnphotocapture;}
Then complete the shot when you press a button:
Private Async void Btncapturephoto_click (object sender, RoutedEventArgs e) { varawait KnownFolders.PicturesLibrary.CreateFileAsync ("photo.jpg", Creationcollisionoption.generateuniquename); await Photocapture.capturephototostoragefileasync (imgencodingproperties, photo);}
You can also add events for phone entity keys:
hardwarebuttons.camerahalfpressed + = hardwarebuttons_camerahalfpressed; Async void Hardwarebuttons_camerahalfpressed (object sender, Cameraeventargs e) { await PhotoCapture.VideoDeviceController.FocusControl.FocusAsync ();}
Finally, remember to release the MediaCapture resource when you leave the page:
protected Override void Onnavigatedfrom (NavigationEventArgs e) { ifnull ) { Photocapture.dispose (); NULL ; }}
(2) Editing photos
I've used the Nokia Imaging SDK and Writablebitmapex library here to search and install in Nuget.
Note To change the CPU in Configuration Manager to ARM, the Nokia Imaging SDK will not be available.
The use of the method is very simple, such as the following for a picture to add a filter:
WriteableBitmap Originbitmap; WriteableBitmap Editedbitmap;Private Async voidEditbutton_click (Objectsender, RoutedEventArgs e) { varImageSource =NewBitmapimagesource (Originbitmap.asbitmap ()); using(varEffect =NewFilterEffect (ImageSource)) { varFilter =NewAntiquefilter (); Effect. Filters=New[] {filter}; varRenderer =Newwriteablebitmaprenderer (effect, originbitmap); Editedbitmap=awaitrenderer. Renderasync (); Editedbitmap.invalidate (); } Myimage.source=Editedbitmap;}
More ways to use the Nokia Help Center view: Links