简体   繁体   English

显示从avcapture捕获的图像

[英]Display captured image from avcapture

I want to store and retrieve an image that was taken from my avcapturesession. 我想存储和检索从我的avcapturesession中拍摄的图像。 I was able to do this with a button press but I want to have the image appear automatically after it is taken. 我能够通过按下按钮来执行此操作,但是我希望图像在拍摄后自动显示。 It works fine with an IBAction press. 它可以与IBAction印刷机配合使用。 Here's what I have done. 这就是我所做的。 I stored the image to user defaults with this code 我使用此代码将图像存储到用户默认设置

UIImage *Capture = [UIImage imageWithData:self.jpegPhotoData];
capturetest = Capture;
NSData *imageData;
imageData = [NSKeyedArchiver archivedDataWithRootObject:Capture];
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"image"];

Then I called the NSUserDefaults with a button press using this code. 然后我使用此代码通过按下按钮来调用NSUserDefaults。

-(IBAction)test:(id)sender
{
    NSLog(@"WAS IT PRESSED");
    NSData *imageData1;
    imageData1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
    capturetest = [NSKeyedUnarchiver unarchiveObjectWithData: imageData1];
    self.imgView.image = capture test;
}

This worked perfect. 这工作完美。 When I pressed the button it showed the image I just took but how do I just get the image to appear automatically? 当我按下按钮时,它会显示我刚刚拍摄的图像,但是如何使图像自动显示呢? I've tried putting the button code inside a void statement like -(void)test then after the photo was taken I called [self test] . 我试过将按钮代码放在像-(void)test这样的void语句中,然后在拍照后我叫[self test] That didn't work. 那没用。 I even tried to call the button press automatically like this but no luck. 我什至试图像这样自动调用按钮,但是没有运气。

[self performSelector: @selector(test:) withObject:self afterDelay: 0.0];
UIImage *Capture = [UIImage imageWithData:self.jpegPhotoData];
globalObject = Capture;

You could do one thing that take one temporary global UIImage object and when you taken picture then you can save image to that object and use whenever you want. 您可以做一件事,即拍摄一个临时全局UIImage对象,然后在拍摄图片时将图像保存到该对象并在需要时使用。

Write a delegate which return the image to required controller,like 编写一个将图像返回给所需控制器的委托,例如

YourImageController.h YourImageController.h

@protocol ImageSendingDelegate <NSObject>

 -(void)ServiceResponse :(UIImage *)currentImage;
@end

@interface YourImageController : .......

@property(strong,nonatomic)id <ImageSendingDelegate>IDelegate;

YourImageController.m Where you get image data YourImageController.m在哪里获取图像数据

UIimage *image = [UIImage imageWithData:self.photoData];

[_IDelegate ServiceResponse:image];

import YourImageController.h in DesireController.h 在DesireController.h中导入YourImageController.h

@interface DesireController : UIViewController<ImageSendingDelegate>

@property (strong,nonatomic)YourImageController *delegateObject;

DesireCOntroller.m DesireCOntroller.m

 if(_delegateObject==nil)
 {
 _delegateObject=[[YourImageController alloc]init];

  _delegateObject.IDelegate=self

 }

-(void)ServiceResponse:(UIImage *)currentImage
{

UIimage *IamgeRecived=currentImage;

NSLog(@"\n\n\n\n geting image");

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM