我想存储和检索从我的avcapturesession中获取的图像。我可以通过按下按钮来执行此操作,但我想让图像在拍摄后自动显示。它可以与IBAction印刷机一起使用。这就是我所做的。我使用此代码将图像存储到用户默认值
UIImage *Capture = [UIImage imageWithData:self.jpegPhotoData];
capturetest = Capture;
NSData *imageData;
imageData = [NSKeyedArchiver archivedDataWithRootObject:Capture];
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"image"];
然后我使用此代码按下按钮调用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;
}
这很完美。当我按下按钮时,它显示了我刚拍摄的图像,但是如何让图像自动显示?我已经尝试将按钮代码放在像-(void)test
这样的void语句中,然后在拍照后我调用了[self test]
。那没用。我甚至试图像这样自动按下按钮,但没有运气。
[self performSelector: @selector(test:) withObject:self afterDelay: 0.0];
答案 0 :(得分:0)
UIImage *Capture = [UIImage imageWithData:self.jpegPhotoData];
globalObject = Capture;
你可以做一件事,拿一个临时的全局UIImage对象,当你拍照时,你可以将图像保存到该对象并随时使用。
答案 1 :(得分:0)
编写一个委托,将图像返回到所需的控制器,如
YourImageController.h
@protocol ImageSendingDelegate <NSObject>
-(void)ServiceResponse :(UIImage *)currentImage;
@end
@interface YourImageController : .......
@property(strong,nonatomic)id <ImageSendingDelegate>IDelegate;
YourImageController.m 你获得图像数据的地方
UIimage *image = [UIImage imageWithData:self.photoData];
[_IDelegate ServiceResponse:image];
在DesireController.h中导入YourImageController.h
@interface DesireController : UIViewController<ImageSendingDelegate>
@property (strong,nonatomic)YourImageController *delegateObject;
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");
}