- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经设置了一个自定义相机 View ,该 View 在 View 上有覆盖按钮。一切正常。相机拍照,图片显示在 UIImageView 中。这张图片在 UIImageView 中后如何保存?
下面的代码:
ViewController.h
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
}
@property (strong, nonatomic) IBOutlet UIView *frameForCapture;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)takePhoto:(id)sender;
@implementation ViewController
AVCaptureSession *session;
AVCaptureStillImageOutput *stillImageOutput;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)viewWillAppear:(BOOL)animated{
session = [[AVCaptureSession alloc]init];
[session setSessionPreset:AVCaptureSessionPresetPhoto];
AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error;
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];
if ([session canAddInput:deviceInput]){
[session addInput:deviceInput];
}
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [[self view]layer];
[rootLayer setMasksToBounds:YES];
CGRect frame = self.frameForCapture.frame;
[previewLayer setFrame:frame];
[rootLayer insertSublayer:previewLayer atIndex:0];
stillImageOutput = [[AVCaptureStillImageOutput alloc]init];
NSDictionary *outputSettings = [[NSDictionary alloc]initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];
[session addOutput:stillImageOutput];
[session startRunning];
}
- (IBAction)takePhoto:(id)sender {
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections){
for (AVCaptureInputPort *port in [connection inputPorts]){
if([[port mediaType] isEqual:AVMediaTypeVideo]){
videoConnection = connection;
break;
}
}
if (videoConnection) {
break;
}
}
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [UIImage imageWithData: imageData];
self.imageView.image = image;
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
最佳答案
您可以使用此功能将图像保存在设备中
UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
关于ios - 如何保存通过 AVCaptureSession 拍摄的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24976019/
我正在开发一个视频录制应用程序,需要能够使用蓝牙麦克风作为音频输入(如果已连接)。 我有以下代码来配置 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
我是一名优秀的程序员,十分优秀!