惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 最新话题
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
S
Security Affairs
H
Hacker News: Front Page
TaoSecurity Blog
TaoSecurity Blog
W
WeLiveSecurity
G
GRAHAM CLULEY
T
Tenable Blog
Schneier on Security
Schneier on Security
S
Securelist
Cyberwarzone
Cyberwarzone
P
Privacy International News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recent Commits to openclaw:main
Recent Commits to openclaw:main
O
OpenAI News
N
News and Events Feed by Topic
AWS News Blog
AWS News Blog
C
Cisco Blogs
T
Threat Research - Cisco Blogs
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
D
DataBreaches.Net
博客园_首页
MyScale Blog
MyScale Blog
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
J
Java Code Geeks
SecWiki News
SecWiki News
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

博客园 - Bruce Lee

Android的界面设计规范-7 Android的界面设计规范-6 Android的界面设计规范-5 Android的界面设计规范-4 Android的界面设计规范-3 Android的界面设计规范-2 Android的界面设计规范-1 Monotouch 移动位于键盘下的内容,自动滚动被键盘遮住的内容 RESTful Web Services,客户端Silverlight提交POST数据报错 Monotouch Save Image To Application(保存相册图片到你的应用程序) Monotouch中使用UINavigationController Monotouch 项目选择Storyborads还是XIBs Montouch 定义一个定制的 View Control类 Monotouch 视图管理周期 Montouch多视图的创建与销毁 Monotouch 常用例子代码 Monotouch在IPAD与IPhone使用UIImagePickerController的图片选择不同的代码 Montouch 增加图片到模拟器(Simulator)的相册中 Monotouch Table View 里面动态增加Table View Cell Switch 触发Switch事件 程序崩溃
Monotouch Copy item from album(从相册拷贝文件出来)
Bruce Lee · 2012-10-20 · via 博客园 - Bruce Lee

项目中需要采集视频、照片、录音,并上传到服务器,这就需要读取这些文件流,照片和录音都很容易搞定。

视频有些麻烦,因为录制的视频被存到相册内,之后在FinishedPickingMedia里面不像照片可以通过下面代码直接得到

UIImage image = (UIImage)info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));

所以想到要不就直接去读取相册的文件,在模拟器内测试成功。

   1: public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info)
   2: {
   3:     //图片之前有方法读取了,这里主要是测试视频,下面是相册内的视频地址,很容易用代码得到的
   4:     //主要是在模拟器中选取视频,点击use后不能触发这个事件,不知道是不是模拟器的bug,所以固定下面视频地址,然后选择图片来执行下面代码
   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:                     //拷贝ALAsset的一定字节到一个缓冲中
  21:                     asset.DefaultRepresentation.GetBytes(buffer, 0, (uint)size, out nsError);
  22:                     吧缓冲写入到byte
  23:                     Marshal.Copy(buffer, imgData, 0, imgData.Length);
  24:                     //可以写成文件,或发送字节流等动作
  25:                     File.WriteAllBytes(filePath1, imgData);
  26:                 }
  27:  
  28:             }, (error) =>
  29:             {
  30:                 if (error != null)
  31:                 {
  32:                     Console.WriteLine("错误: " + error.LocalizedDescription);
  33:                 }
  34:             });
  35:         });
  36:     }
  37:     picker.DismissModalViewControllerAnimated(true);
  38: }

作者:Bruce Lee
出处:http://www.cnblogs.com/BruceLee521
本博原创文章版权归博客园和本人共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出作者名称和原文连接,否则保留追究法律责任的权利。