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

推荐订阅源

P
Proofpoint News Feed
WordPress大学
WordPress大学
Help Net Security
Help Net Security
Jina AI
Jina AI
Security Latest
Security Latest
Y
Y Combinator Blog
Project Zero
Project Zero
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
博客园 - 司徒正美
MyScale Blog
MyScale Blog
Cyberwarzone
Cyberwarzone
D
Docker
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
LangChain Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
The Hacker News
The Hacker News
C
Check Point Blog
L
Lohrmann on Cybersecurity
V2EX - 技术
V2EX - 技术
S
Securelist
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
Latest news
Latest news
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Register - Security
The Register - Security
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
小众软件
小众软件
T
Tailwind CSS Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
宝玉的分享
宝玉的分享
O
OpenAI News

博客园 - 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
本博原创文章版权归博客园和本人共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出作者名称和原文连接,否则保留追究法律责任的权利。