- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在从 AVCaptureSession 相机中的 CMSampleBuffer 释放内存时遇到问题。这是我设置捕获 session 的代码。如果我处置 imageDataSampleBuffer,应用程序会崩溃。
using MonoTouch.CoreVideo;
using MonoTouch.CoreMedia;
using MonoTouch.AVFoundation;
using MonoTouch.ImageIO;
using MonoTouch.UIKit;
using MonoTouch.CoreFoundation;
using MonoTouch.Foundation;
using System.Drawing;
using System;
namespace myNamespace
{
public class AVFoundationCamera : UIViewController
{
public AVFoundationCamera (CameraController parView)
{
parentView = parView;
}
NSError error;
AVCaptureSession session;
AVCaptureDevice device;
AVCaptureDeviceInput input;
AVCaptureStillImageOutput output;
AVCaptureVideoPreviewLayer captureVideoPreviewLayer;
NSDictionary outputSettings;
AVCaptureConnection captureConnection;
UIButton buttCaptureImage;
public UIImageView imageV;
NSData imageData;
CameraController parentView;
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
CreateControls();
SetupSession();
}
public override void DidReceiveMemoryWarning ()
{
imageData.Dispose();
session.Dispose();
device.Dispose();
input.Dispose();
output.Dispose();
captureVideoPreviewLayer.Dispose();
base.DidReceiveMemoryWarning ();
}
private void CreateControls()
{
imageV = new UIImageView(new RectangleF(0, 0, UIScreen.MainScreen.ApplicationFrame.Width, UIScreen.MainScreen.ApplicationFrame.Height - UIApplication.SharedApplication.StatusBarFrame.Height));
View.AddSubview(imageV);
buttCaptureImage = UIButton.FromType(UIButtonType.RoundedRect);
buttCaptureImage.Frame = new RectangleF(0, 60, 150, 30);
buttCaptureImage.SetTitle("Take a photo", UIControlState.Normal);
buttCaptureImage.TouchUpInside += HandleButtCaptureImageTouchUpInside;
View.AddSubview(buttCaptureImage);
}
void HandleButtCaptureImageTouchUpInside (object sender, EventArgs e)
{
captureConnection = null;
foreach (AVCaptureConnection capConn in output.Connections)
{
foreach (AVCaptureInputPort port in capConn.inputPorts)
{
if (port.MediaType == AVMediaType.Video)
{
captureConnection = capConn;
break;
}
}
if (captureConnection != null)
break;
}
output.CaptureStillImageAsynchronously(captureConnection, HandleAVCaptureCompletionHandlercompletionHandler);
buttCaptureImage.Enabled = false;
}
void HandleAVCaptureCompletionHandlercompletionHandler (CMSampleBuffer imageDataSampleBuffer, NSError error)
{
try
{
using (var pool = new NSAutoreleasePool ()) {
imageData = AVCaptureStillImageOutput.JpegStillToNSData(imageDataSampleBuffer);
//imageDataSampleBuffer.Dispose();
parentView.DismissModalViewControllerAnimated(true);
parentView.HandlePickedImage(imageData);
session.StopRunning();
}
}
catch (Exception exc)
{
Console.WriteLine(exc);
}
}
private void SetupSession()
{
session = new AVCaptureSession();
session.BeginConfiguration();
session.SessionPreset = AVCaptureSession.PresetPhoto;
captureVideoPreviewLayer = new AVCaptureVideoPreviewLayer(session);
captureVideoPreviewLayer.Frame = imageV.Bounds;
imageV.Layer.AddSublayer(captureVideoPreviewLayer);
device = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
input = new AVCaptureDeviceInput(device, out error);
session.AddInput(input);
output = new AVCaptureStillImageOutput();
output.OutputSettings = NSDictionary.FromObjectAndKey(new NSString("AVVideoCodecKey"), new NSString("AVVideoCodecJPEG"));
session.AddOutput(output);
session.CommitConfiguration();
session.StartRunning();
}
}
这只是一个用于拍照的普通相机。我尝试使用您在此处发布的 UIImagePickerController:https://github.com/migueldeicaza/TweetStation/blob/master/TweetStation/UI/Camera.cs这消除了 UIImagePickerController 错误,但每当我单击“拍照”按钮时,都会显示分配内存的预览窗口。如果我按下“Retake”,内存将被释放,但在 FinishedPiCkingMedia 事件处理程序中我无法释放它。所以,几张照片后它崩溃了。
任何解决方案都适合我,但很高兴看到我做错了什么。
再次感谢您。
最佳答案
这是一个 bug在 MonoTouch 中。
在获得修复之前,您可以使用一种解决方法:
[DllImport ("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
extern static void CFRetain (IntPtr handle);
void HandleAVCaptureCompletionHandlercompletionHandler (CMSampleBuffer imageDataSampleBuffer, NSError error)
{
try {
CFRetain (imageDataSampleBuffer.Handle);
(...)
} finally {
imageDataSampleBuffer.Dispose ();
}
}
我已经添加了一个 Dispose 调用,可用缓冲区的数量可能有限,这样您可以确保应用程序不会耗尽它们(因为 GC 可能需要一些时间才能自动释放它)
另请注意,一旦安装了带有真正修复程序的 MonoTouch 版本,就应该删除解决方法,否则会泄漏缓冲区。
关于ios - AVCaptureSession CMSampleBuffer 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050882/
我正在开发一个视频录制应用程序,需要能够使用蓝牙麦克风作为音频输入(如果已连接)。 我有以下代码来配置 AVCaptureSession 的音频输入: self.captureSession.uses
对于这个“愚蠢”的问题,我提前表示歉意,但我觉得我已经用尽了所有资源。我对 Swift 和一般编码几乎没有经验,但根据过去的经验和基于对象的编程(如 MAX MSP)的使用,我了解了很多。 我正在尝试
我正在尝试将捕获的帧记录为视频,同时并行地对帧执行图像处理任务。 我有一个 AVCaptureSession,我已将两个单独的输出添加到 - AVCaptureVideoDataOutput AVCa
当我尝试构建我的应用程序时,XCode 向我显示此错误 AVCaptureSession 之前应有“(” 有人可以帮我解决这个警告吗?这是我的代码: ViewController.h #import
我能够根据 http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html 使用 AVCaptureSession 从相机捕获视频帧。但
我正在开发一个处理高清照片的应用程序。我正在使用 AVCaptureSession 拍照,停止它,然后对该照片应用效果。 让我疯狂的是,一切都运行良好,仪器告诉我,我正确且按时地释放了我使用的所有内存
我正在构建一个应用程序,允许用户使用 iPhone 相机拍照,并在可用时使用 AVFoundation (iOS4),以便用户可以使用点击对焦功能,即使使用自定义叠加层也是如此。 我遇到的问题是cap
所以这是一个普遍问题,但我们正在寻找有关如何让实时相机 View 能够在顶部添加图像并拍照的线索。所以基本上你可以选择像“帽子”一样覆盖在相机上的图像,调整其大小和位置,然后拍照,“帽子”将出现在你拍
我正在做一个 iOS 应用程序,需要使用这样的层次结构对 QR 码进行验证: View ---Scan View ---Image View - cardBG ---Inside View 加载 Vi
我正在尝试使用 AVCaptureSession 制作自定义相机。 代码和一切工作正常。唯一的问题是 VideoOutput 层被缩放。这使我的照片默认缩放。 我尝试了每件事,但无法找到解决方案。这是
我正在使用 AVCaptureSession 创建带有 AVCaptureMetadataOutput 的 QR 码扫描仪。 一切都按预期工作,但是我想在扫描仪上放置图形叠加层。这样做时,我希望扫描仪
弹出 View Controller 时,我在使用 AVCaptureSession 时遇到一些困难。我在导航 Controller 中有一个 View Controller ,用户可以在其中拍照。捕
有人知道如何使用 AVFoundation (AVCaptureStillImageOutput) 在自定义 iOS 相机中设置自定义分辨率吗? 我知道您可以使用 AVCaptureSession 选
我需要做这样的事情。我的应用程序使用 AVCapturesession 进行录制,但它应该能够流式传输带有我播放过的背景音乐的实时提要。 请记住,我可以使用 AVCapturesession 播放背景
当 AVCaptureSession 的 session 运行到本地 NSMutableArray 中捕获图像时,我收到 didReceiveMemoryWarning 调用。稍作测试后,我发现它发生
我正在尝试将 AVCaptureSession 的音频静音和取消静音。开始 session 后,我可以启用和禁用音频连接,但是一旦我播放视频,所有音频部分都会被推回视频的前面,只留下视频的结尾没有声音
我已经为 ios 应用程序添加了二维码阅读器代码现在我想使用可以用作 ios 中的 Today 扩展的相同代码。我已将以下代码用于应用程序和扩展。该应用程序运行良好,但不适用于扩展程序。 我用过htt
如何使用 AVCaptureSession 录制方形视频?如果在录制时不可能,那么我如何在 didFinishRecordingTo 委托(delegate)方法中裁剪它? 提前致谢! 最佳答案 您可
我收到一条警告: (sending "ViewController *const_strong' to parameter of incompatible type 'id' 执行这行代码时 [out
在我的应用程序中,我录制长达 30 秒的视频。我使用以下行来执行此操作。 [imagePicker setVideoMaximumDuration:30]; 一切正常。然后我决定从 UIImagePi
我是一名优秀的程序员,十分优秀!