The project needs to collect videos, photos, and recordings and upload them to the server. This requires reading these file streams, and the photos and recordings are easily handled.
The video is a little troublesome because the recorded video is saved in the album and then in finishedpickingmedia, unlike the photo, you can get it directly using the following code.
Uiimage image = (uiimage) info. objectforkey (New nsstring ("uiimagepickercontrolleroriginalimage "));
Therefore, if you want to directly read the album file, the test is successful in the simulator.
1: public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info)
2: {
3: // you can read the image. Here we mainly test the video. below is the video address in the album, which is easily obtained by code.
4: // select a video in the simulator. After you click use, this event cannot be triggered. I don't know if it is a simulator bug. So fix the following video address and select an image to execute the following code.
5: NSUrl referenceURL = new NSUrl("assets-library://asset/asset.mov?id=5F4A9F73-3542-469F-8DAD-BC2B53BFB40C&ext=mov");
6: if (referenceURL != null)
7: {
8: ThreadPool.QueueUserWorkItem(delegate
9: {
10: ALAssetsLibrary library = new ALAssetsLibrary();
11: library.AssetForUrl(referenceURL, (asset) =>
12: {
13: if (asset != null)
14: {
15: string filePath1 = Path.Combine(destPath, asset.DefaultRepresentation.Filename);
16: long size = asset.DefaultRepresentation.Size;
17: byte[] imgData = new byte[size];
18: NSError nsError;
19: IntPtr buffer = Marshal.AllocHGlobal(imgData.Length);
20: // copy a certain byte of alasset to a buffer
21: asset.DefaultRepresentation.GetBytes(buffer, 0, (uint)size, out nsError);
22: write buffer to byte
23: Marshal.Copy(buffer, imgData, 0, imgData.Length);
24: // you can write files or send byte streams.
25: File.WriteAllBytes(filePath1, imgData);
26: }
27:
28: }, (error) =>
29: {
30: if (error != null)
31: {
32: console. writeline ("error:" + error. localizeddescription );
33: }
34: });
35: });
36: }
37: picker.DismissModalViewControllerAnimated(true);
38: }
By Bruce Lee
Source: http://www.cnblogs.com/BruceLee521
This blog Original article is copyrighted by the blog and I share it with you. You are welcome to reprint it. However, you must keep this statement without the author's consent and provide the author name and original article connection clearly on the article page, otherwise, you are entitled to pursue legal liability.