我想通过应用程序使用相机单击照片。然后将照片存储在应用程序中。可能吗?任何人都可以告诉我如何实现这一目标。我还想知道.EXIF数据是否会与图像一起保留。请帮助。
答案 0 :(得分:3)
这个概念从应用程序&以后使用它们
1
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextRef context = UIGraphicsGetCurrentContext();
UIImageWriteToSavedPhotosAlbum(saveImage, self, @selector(image:didFinishSavingWithError:contextInfo:), &context);
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(saveImage);
NSString *imageName = @"temp.png";
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPathToFile atomically:NO];
Above code takes screenshot of the view & save this image in the documentsDirectory as "temp.png"
2
NSInteger primaryKeyValue = 1;
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"temp.png"];
NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"%d.png",primaryKeyValue ]];
NSFileManager *fileMgr = [NSFileManager defaultManager];
[fileMgr moveItemAtPath:fullPathToFile toPath:filePath2 error:nil];
3。 稍后,如果你想使用这个图像
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *uniquePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat: @"%d.png",primaryKeyValue ]];
UIImage *image = [UIImage imageWithContentsOfFile:uniquePath];